Angularjs 我使用的是MEAN.IO堆栈,为什么可以';我不能使用require访问我的数据访问层吗?

Angularjs 我使用的是MEAN.IO堆栈,为什么可以';我不能使用require访问我的数据访问层吗?,angularjs,express,angular-ui-router,mean.io,Angularjs,Express,Angular Ui Router,Mean.io,因此,我使用的是mean.io,出于某种原因,我的routes.js从不使用我的'index.all'方法或'exports.all'函数,即使我需要服务器端控制器的函数。另外,我的路由是使用AngularUI路由器完成的。有人知道如何在MEAN.IO中通过路由调用后端方法吗?我一直在使用: 'use strict'; module.exports = function(System, app, auth, database) { // Home route

因此,我使用的是mean.io,出于某种原因,我的routes.js从不使用我的'index.all'方法或'exports.all'函数,即使我需要服务器端控制器的函数。另外,我的路由是使用AngularUI路由器完成的。有人知道如何在MEAN.IO中通过路由调用后端方法吗?我一直在使用:

 'use strict';

    module.exports = function(System, app, auth, database) {

        // Home route
        var index = require('../controllers/index');
 app.route('/test').get(index.all);
        app.route('/')
            .get(index.render);

    };
我想点击“index.all”,但即使我导航到/test,它仍然会 index.render。有人知道为什么吗

以下是控制器文件:

 'use strict';

    var mean = require('meanio');
    var mongoose = require('mongoose');
    var Composition = mongoose.model('Composition');

    exports.render = function(req, res) {
    console.log(req.user);
        var modules = [];
        // Preparing angular modules list with dependencies
        for (var name in mean.modules) {
            modules.push({
                name: name,
                module: 'mean.' + name,
                angularDependencies: mean.modules[name].angularDependencies
            });
        }

        function isAdmin() {
            return req.user && req.user.roles.indexOf('admin') !== -1;
        }


        // Send some basic starting info to the view    
        res.render('index', {
            user: req.user ? {
                name: req.user.name,
                _id: req.user._id,
                username: req.user.username,
                roles: req.user.roles
            } : {},
            modules: modules,
            isAdmin: isAdmin,
            adminEnabled: isAdmin() && mean.moduleEnabled('mean-admin')
        });
    };

    exports.all = function(req, res) {

        console.log(req.user);
        Composition.find({user: req.user}, 'title description').sort('-created').populate('user', 'name username').exec(function(err, compositions) {
            if (err) {
                return res.jsonp(500, {
                    error: 'Cannot list the compositions'
                });
            }
            res.jsonp(compositions);

        });
    };

这是前端还是后端问题?感谢您提供的任何可能有用的建议。

您正在浏览。那么,您是否正在点击浏览器url中的链接?然后您应该尝试
localhost:3000/test
而不是l
ocalhost:3000/#/测试

表单
localhost:3000://#的URL/是有角度的路线。查看角度布线和视图。使用角度视图比服务器端渲染更好。对
测试执行角度布线
,并添加与之对应的视图。使用常规的
$http.get
调用获取视图中的动态数据


选中此项,查看您正在导航的angular

中的布线和添加视图。那么,您是否正在点击浏览器url中的链接?那么您应该尝试localhost:3000/test而不是localhost:3000/#/test@ma08当我执行localhost:3000/test时,它可以工作,但之后我就无法获得我的模板。我确实找到了我想要的快速方法。我想,从我的快速路由,如果我导航到一个位置是/测试,我应该点击该方法。它与主导航“/”一起工作,它获取模板和express方法是有角度的路线。查看角度布线和视图。使用角度视图比服务器端渲染更好。为测试执行角度布线,并添加与之对应的视图。使用常规的$http.get调用获取视图中的动态数据。谢谢!我已经在这个问题上纠缠了一段时间了,多亏了你,它工作了!!!耶!!!你真棒!我知道角度路由是如何工作的,但让我着迷的是服务注入。教程帮助我把它粘在一起,但我想我会对angular的服务做更多的研究。再次感谢:)