This is quite dummy question, but I can’t figure it out. I have some simple module, configure like this:
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;});
});
Now in SpecPoolCtrl:
function SpecificationCtrl($scope, foo,$http, $location, $routeParams) {
window.console.log($scope.foo());
...
}
When I run this code, I’m getting
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)
Can you help me what’s wrong? Or some related example how to make it work?
You should use it like
This is because
fooisn’t defined in your SpecificationCtrl$scope, it’s being injected so you can use it by just writingfooas mentioned above.Also, if you were to minify your code, please consider injection array syntax.
Here is the plunker