简体   繁体   English

Meanjs路由到服务器控制器

[英]meanjs route to server controller

i am trying to add a new method to my controller "matches.server.controller" names listTeams. 我试图将新方法添加到我的控制器“ matches.server.controller”命名为listTeams的方法中。 I have added a new route to the matches.server.route.js file like this 我已经将新的路由添加到matchs.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);
};

this is the method in my server controller: 这是我的服务器控制器中的方法:

exports.listteams = function(req, res) {
    res.json(1);
};

In matches.client.controller i call the method like this: 在matches.client.controller中,我这样调用方法:

 $scope.listteams = function(){
        $scope.teams = Matches.get('matches/listTeams').success(function(data){
            var d = data;
        }).error(function(data){
            var d = data;
        });

however when i debug i always come in the list method of matches and not in listTeams method What am i doing wrong? 但是,当我调试时,我总是出现在匹配项的列表方法中,而不是在listTeams方法中。我在做什么错?

Maybe it's because you are duplicating the path name 可能是因为您正在复制路径名

All parameters that goes after '/matches/' is handling by '/matches/'之后'/matches/'所有参数都由

app.route('/matches/:matchId')
    .get(matches.read)
    .put(users.requiresLogin, matches.hasAuthorization, matches.update)
    .delete(users.requiresLogin, matches.hasAuthorization, matches.delete);

and perceiving like argument of '/:matchId' '/:matchId''/:matchId'

In your case: find me team with id "listTeams" 您的情况: find me team with id "listTeams"

Try to rename your path from matches to smth else like 尝试将您的matches路径重命名为其他名称

module.exports = function(app) {
// Match Routes
app.route('/smthelse_not_matches/listTeams')   <-- new route added here !!
    .get(matches.listteams);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM