meanjs路由到服务器控制器
我想添加一个新的方法到我的控制器“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); };
这是我的服务器控制器中的方法:
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; });
然而,当我debugging我总是在列表方法的匹配,而不是在listTeams方法我做错了什么?
也许这是因为你正在复制path名
在'/matches/'
之后'/matches/'
所有参数都是通过处理的
app.route('/matches/:matchId') .get(matches.read) .put(users.requiresLogin, matches.hasAuthorization, matches.update) .delete(users.requiresLogin, matches.hasAuthorization, matches.delete);
并'/:matchId'
像'/:matchId'
在你的情况: find me team with id "listTeams"
尝试重新命名你的path从matches
到其他像
module.exports = function(app) { // Match Routes app.route('/smthelse_not_matches/listTeams') <-- new route added here !! .get(matches.listteams);
- ExpressJs与Angular2项目的文件结构
- LoopBack存储服务,直接上传(无需请求对象)
- 如果当前用户的ID与所述路由中的ID匹配,如何才允许访问路由? 的NodeJS
- 如何使用羽毛/快递使用webpack-dev-middleware?
- 用户和angular色授权在swigger api express中
- 节点 – expression太多的redirect
- 使用node和express服务获取(/ foo /:bar)请求,当res.render(模板)时,模板中的所有相对链接都是相对于/ foo而不是/
- NodeJS Express – 单独处理404(Not Found)和405(Method Not Allowed)
- 在节点js中正确使用asynchronous