haakon319 haakon319 - 11 months ago 47
Javascript Question

Why is call to factory in angular occuring 3 times on load?

I have a factory in my angular code that I call from my controller like this:

$scope.result = themefactory.someMethod();
console.log('results are ' + $scope.result);

When I open my page and look at my console I'm seeing that this runs 3 times on page load? It seems silly to make the call 3 times? How can I prevent this from happening?

Answer Source

Check if you are not loading the controller twice like this:

.state('signin', {
    url: '/entrar',
    templateUrl: 'auth/views/_login.html',
    controller: 'TestController'

And like this: ng-controller="TestController"

That might eliminate one execution, need more details for the other...