Angularjs 将MongoDB与Restanglar一起使用

Angularjs 将MongoDB与Restanglar一起使用,angularjs,node.js,mongodb,rest,restangular,Angularjs,Node.js,Mongodb,Rest,Restangular,我是新来的吝啬鬼,现在我有一个我无法解决的问题。在服务器端为express提供RESTAPI,我正在使用库。我有一个模式Sport.js: var mongoose = require('mongoose'); // create a schema var SportSchema = new mongoose.Schema({ name: { type: String, required: true } }); // export the mo

我是新来的吝啬鬼,现在我有一个我无法解决的问题。在服务器端为express提供RESTAPI,我正在使用库。我有一个模式Sport.js:

var mongoose = require('mongoose');

// create a schema
var SportSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    }
});

// export the model schema
module.exports = SportSchema;
和控制器SportController.js

var restful = require('node-restful');

module.exports = function (app, route) {

    // setup the controller for REST
    var rest = restful.model(
        'sport',
        app.models.sport
    ).methods(['get', 'put', 'post', 'delete']);

    // register the endpoint with the application
    rest.register(app, route);

    // return middleware
    return function (req, res, next) {
        next();
    };
};
在客户端,我使用library作为AngularJS服务来处理RESTAPI Restful资源。下面是使用它的controller main.js:

angular.module('clientApp')
    .controller('MainCtrl', function ($scope, Sport) {

        $scope.sports = Sport.getList().$object;
        console.log($scope);

    });
在Firebug中,我看到了对象$scope,因此工作正常,而且我可以在模板中使用对象$scope.sports。但我想在这里使用mongoosejs的命令,例如

angular.module('clientApp')
    .controller('MainCtrl', function ($scope, Sport) {

        // find each sport with a name matching 'Run'
        Sport.findOne({ 'name': 'Run' }, function (err, sport) {
            if (err) return handleError(err);
            console.log(sport.name); // <-- does not work
        });

        $scope.sports = Sport.getList().$object;
        //console.log($scope);

});

有可能吗?我真的是个新手,所以如果我做错了什么,我道歉。

那么你有一个功能强大的MongoDB,你现在只想列出一个包含“Run”的运动

在html元素中放置一个ng模型,该元素应该对输出进行处理。假设要在列表中列出包含跑步的所有运动:


不,你不能那样做。Sport是restangular对象,所以您只能调用它的方法,它不知道您是否正在使用mongo节点或任何东西。。。它所知道的一切意味着。。。
<any-html ng-model="findonly.name" value="Run">
<input ng-model="searchSport.name" placeholder="Search for sports by name">
<table> <th>...</th> 
<tr ng-repeat="Sport in sports" | filter:searchSport.name:strict"> <td> {{Sport.name}}
</td></tr></table>
filter:findonly.name:strict"