我正在尝试向我的 Controller “matches.server.controller”名称 listTeams 添加一个新方法。 我已经向 matches.server.route.js 文件添加了一条新路由,如下所示
'use strict';
/**
* Module dependencies.
*/
var users = require('../../app/controllers/users.server.controller'),
matches = require('../../app/controllers/matches.server.controller');
module.exports = function(app) {
// Match Routes
app.route('/matches/listTeams') <-- new route added here !!
.get(matches.listteams);
app.route('/matches')
.get(matches.list)
.post(users.requiresLogin, matches.create);
app.route('/matches/:matchId')
.get(matches.read)
.put(users.requiresLogin, matches.hasAuthorization, matches.update)
.delete(users.requiresLogin, matches.hasAuthorization, matches.delete);
// Finish by binding the matches middleware
app.param('matchId', matches.matchByID);
};
这是我的服务器 Controller 中的方法:
exports.listteams = function(req, res) {
res.json(1);
};
在 matches.client.controller 中,我调用如下方法:
$scope.listteams = function(){
$scope.teams = Matches.get('matches/listTeams').success(function(data){
var d = data;
}).error(function(data){
var d = data;
});
但是,当我调试时,我总是进入匹配列表方法,而不是进入 listTeams 方法 我做错了什么?
最佳答案
可能是因为你复制了路径名
'/matches/'
之后的所有参数均由
app.route('/matches/:matchId')
.get(matches.read)
.put(users.requiresLogin, matches.hasAuthorization, matches.update)
.delete(users.requiresLogin, matches.hasAuthorization, matches.delete);
并感知'/:matchId'的参数
在您的情况下:找到 ID 为“listTeams”的团队
尝试将路径从 matches
重命名为 smth else,例如
module.exports = function(app) {
// Match Routes
app.route('/smthelse_not_matches/listTeams') <-- new route added here !!
.get(matches.listteams);
关于angularjs - meanjs 路由到服务器 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27591314/