这是一个非常愚蠢的问题,但我无法弄清楚。我有一些简单的模块,配置如下:
var synergy_module = angular.module('synergy', [])
.config(function($provide, $routeProvider) {
$routeProvider.when('/s/:id', {templateUrl: 'partials/...', controller: SpecPoolCtrl});
$routeProvider.when('/s', {templateUrl: 'partials/...', controller: SpecPoolCtrl});
$provide.factory('foo', function(){return 1;});
});
现在在 SpecPoolCtrl 中:
function SpecificationCtrl($scope, foo,$http, $location, $routeParams) {
window.console.log($scope.foo());
...
}
当我运行这段代码时,我得到
TypeError: Object #<Object> has no method 'foo'
at new SpecificationCtrl (app/js/controllers.js:373:31)
at invoke (app/lib/angular/angular.js:2795:28)
at Object.instantiate (app/lib/angular/angular.js:2805:23)
at $get (app/lib/angular/angular.js:4621:24)
你能帮我看看有什么问题吗?或者一些相关的例子如何使它工作?