AngularJs: controller is called twice by using $routeProvider AngularJs: controller is called twice by using $routeProvider angularjs angularjs

AngularJs: controller is called twice by using $routeProvider


I had face same issue today. I had added controller name in my $routeProvider and also in my html.

$routeProvider    .when('/login', {            controller: 'LoginController',            templateUrl: 'html/views/log-in.html'     })

and in my view as

<div class="personalDetails" ng-controller="LoginController"> </div>

You can remove controller name either from your view or from your routeprovider.


I had the same problem , and it seems there is a stupid bug with routing. There is some kind of redirection going on.

to fix it , i just added a slash in the href , like :

<li><a href="#/build-content/"></a></li>

I hope it will fix things for you too.


I've had a similar problem. I found adding a trailing slash in the route but not in the link worked as expected.

$routeProvider.when('/build-content/',...);

With this markup

<li><a href="/build-content">Content</a></li>

And then AngularJS will correct the URL in the browser to what is defined in the $routeProvider.

Bizarrely the opposite seems to work too with a trailing slash in the link and not in the route. It seems as long as the trailing slashes don't match the resolves and controller won't be called twice!