0
我試圖從我的MySql數據庫檢索一些數據到我的Angular控制器通過節點/快遞,但我有一些路由問題。從MySql數據庫檢索數據通過快遞和角
在相位控制器我有做一個GET請求的負載功能:
$scope.load = function() {
$http.get('/users').
success(function(data, status, headers, config) {
console.log('success');
$scope.todos = data;
console.log(data);
console.log($scope.todos);
}).
catch(function(data, status, headers, config) {
console.log('catch');
console.log(status);
console.log(data);
});
};
在我app.js我:
var users = require('./routes/users');
app.use('/users', users);
在我的路線/ users.js文件我有:
var express = require('express');
var router = express.Router();
var pool = require('../connection');
/* GET users listing. */
router.get('/users', function(req, res, next) {
pool.getConnection(function(err, connection){
connection.query('SELECT * FROM `users` WHERE `first_name` = "Kees"', function(err, results){
if(err) {
throw err;
}else{
console.log(results);
}
});
connection.release();
});
});
module.exports = router;
當我火load()函數在我看來,app.js數收益:
GET /用戶404 54.369毫秒 - 1846
而瀏覽器顯示:
GET http://localhost:3000/users 404(未找到)
捕獲
對象{數據: 「」,status:404,config:Object,statusText:「Not Found」}
什麼是通過Express檢索數據的正確方法?