Express JS:Params undefined

时间:2016-10-24 04:02:58

标签: javascript node.js express

我在快递js中有以下路线

app.get('/fetchnotes/:id', function(req, res) {
    var id = req.params.id;
    console.log(id);
    connection.query('SELECT * from dn_notes where id=?',[id], function(err, rows, fields) {
        if (!err) {
            res.json(rows);
        } else {
            console.log(err);
        }
    });
});

我在HTML文件中有以下代码,它将使用参数

调用fetchnotes
<a class="item item-body" href="#/app/fetchnotes/{{notes.id}}">
    {{notes.detail}}
</a>

app.js

.state('app.fetchsinglenote', {
    url: '/fetchnotes/:notelistid',
    views: {
        'menuContent': {
            templateUrl: 'templates/notelists.html',
            controller: 'SingleNoteListCtrl'
        }
    }
});

controller.js

.controller('SingleNoteListCtrl', function($scope, $state, $resource, $stateParams ) {
    $scope.fetchnotes = {};
    var id = $stateParams .id;
    var Fetchnotes1 = $resource('http://localhost:8080/fetchnotes/'+ id);
    Fetchnotes1.query(function(results) {
        $scope.fetchnotes = results;
    })
})

节点服务器通过端口8080运行。

但是,我在快递js文件中从undefined行的控制台获取console.log(id);的值。问题在哪里?

1 个答案:

答案 0 :(得分:0)

$ resource(&#39; http://localhost:8080/fetchnotes/:notelistid&#39;,{notelistid:&#39; @_ id&#39;}, 尝试以这种方式发送