Module routes:
var switchModule = angular.module(\'switchModule\', []);
switchModule.config([\'$routeProvider\', function($routeProvider) {
$routeProvid
I too had a similar problem with a customDirective and unitentionally duplicated my controller.
<html>
<body ng-app="MyApp" ng-controller="MyDirectiveCtrl">
<my-directive></my-directive>
</body>
</html>
angular.directive('myDirectivie', [function() {
return {
restrict: 'E',
controller: 'MyDirectiveCtrl',
...
}
}]);
I resolved it by removing ng-controller tag at body level
Mine was a case of having 2 ng-view directives. I tried to wrap it, but unintentionally duplicated it:
<div class="ng-view">
<div ng-view></div>
</div>
Removed the wrapper, fixed it.
I had same problem and found that if you bootstrapped you angular two time you can have same error.
In my case I had <body ng-app>
but also angular.bootstrap(document,['app'])
and that caused double initialization of controllers.
Hope this can save some time to someone.
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!