Howard Howard - 1 year ago 105
AngularJS Question

AngularJs: controller is called twice by using $routeProvider

Module routes:

var switchModule = angular.module('switchModule', []);

switchModule.config(['$routeProvider', function($routeProvider) {
when('/build-content', {templateUrl: 'build-content.html', controller: BuildInfoController});


function BuildInfoController($http, $scope){


<html ng-app="switchModule">
<li><a href="#build-content"/></a></li>
<div class="ng-view"></div>

Each time when i click the hyperlink '', the 'BuildInfoController' will be called twice. Am i missing something here?

mpm mpm
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download