David Luque
David Luque

Reputation: 1108

Injecting a factory in Angular

Hello I can't call a factory function. When I use it I have the next message

enter image description here

Here my factory

enter image description here

And the controller with the call

enter image description here

When I try to print Account, it is undefined. Can anyone see my error? Thanks

Upvotes: 1

Views: 58

Answers (1)

z0r
z0r

Reputation: 8595

It's because Account is not declared as a dependency of the controller. Change it to:

.controller('forgotController', ['$scope', '$location', 'Account',
                                 function($scope, $location, Account) {

For this to work, you need to make sure Account is available to the injector for your module. So when you declare the module that your controller is in, if it's not in the same module, be sure to include AccountService as a module dependency. For example:

angular.module('ForgotModule', ['AccountService'])
    .controller('forgotController', ['$scope', '$location', 'Account',
                                     function($scope, $location, Account) {

Upvotes: 3

Related Questions