簡體   English   中英

Meanjs路由到服務器控制器

[英]meanjs route to server controller

我試圖將新方法添加到我的控制器“ matches.server.controller”命名為listTeams的方法中。 我已經將新的路由添加到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);
};

這是我的服務器控制器中的方法:

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/'之后'/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"

嘗試將您的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