【发布时间】:2014-09-03 09:28:04
【问题描述】:
我正在使用猫鼬将对象存储到我的数据库中。我已经成功地将一个对象保存到数据库中,现在每当我尝试搜索它时,我都会在“Compositions.query(function ...”上得到一个未定义的结果。我有这个模块,称为 composition,这是它的控制器:
angular.module('mean.compositions').controller('CompositionsController', ['$scope','fileUpload' ,'$stateParams', '$location', 'Global', 'Compositions',
function($scope, fileUpload, $stateParams, $location, Global, Compositions) {
$scope.global = Global;
$scope.package = {
name: 'compositions'
};
$scope.find = function() {
console.log('get here');
Compositions.query(function(composition) {
console.log(composition);
$scope.composition = composition;
});
console.log('pass');
};
}
现在,每当我尝试查询合成时,都会收到此错误:
undefined is not a function
at Scope.$scope.find (http://localhost:3000/modules/aggregated.js:6:644)
at http://localhost:3000/bower_components/angular/angular.js:10735:21
at Scope.$eval (http://localhost:3000/bower_components/angular/angular.js:12595:28)
at pre (http://localhost:3000/bower_components/angular/angular.js:19781:15)
at nodeLinkFn (http://localhost:3000/bower_components/angular/angular.js:6628:13)
at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:6039:13)
at publicLinkFn (http://localhost:3000/bower_components/angular/angular.js:5934:30)
at http://localhost:3000/bower_components/angular-ui-router/release/angular-ui-router.js:2805:9
at nodeLinkFn (http://localhost:3000/bower_components/angular/angular.js:6648:13)
at compositeLinkFn (http://localhost:3000/bower_components/angular/angular.js:6039:13) <section data-ng-controller="CompositionsController" data-ng-init="find()" class="ng-scope">
我已包含服务代码。
更新:
'use strict';
angular.module('mean.compositions').factory('Compositions', [
function() {
return {
name: 'compositions'
};
}
]);
感谢任何形式的输入,为什么我会收到这个奇怪的错误。
【问题讨论】:
-
您可以发布
Compositions服务吗? -
@AnthonyChu 我已经用服务代码更新了我的帖子。
-
对不起,我的意思是
Compositions服务被注入到控制器中。那是什么以及它是如何定义的? -
@AnthonyChu 我是 Angular 新手,但我认为新的更新应该是您所要求的?
-
是的,就是这个。
Compositions只是一个具有name属性的对象。这就解释了为什么当您尝试调用其不存在的query()方法时会出现该错误。您的意思是从工厂返回资源吗?
标签: node.js angularjs mongoose mean-stack