簡體   English   中英

Express JS:參數未定義

[英]Express JS : Params undefined

我的快遞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運行。

但是我從控制台的console.log(id);行獲得undefined的值console.log(id); 在我的快速js文件中。 有問題的人在哪里?

$ resource(' http:// localhost:8080 / fetchnotes /:notelistid ',{notelistid:'@_id'},嘗試用這種方式發送

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM