Express JS:参数未定义

Express JS : Params undefined

本文关键字:未定义 参数 JS Express      更新时间:2023-09-26

我有以下路线在我的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端口运行。

然而,我在我的express js文件中的console.log(id);行从控制台获得undefined的值。问题在哪里?

$resource('http://localhost:8080/fetchnotes/:notelistid', {notelistid: '@_id'},试着这样发送