单击控制器链接时,我的每个控制器都会执行两次。在我看来,我还没有定义ng-controller。这是我定义路线的app.js:
var app = angular.module('myapp', [ 'ngRoute', 'routeStyles', 'angular-growl' ]);
// Routes
$routeProvider
// PAGES
.when('/about/', {
templateUrl: 'views/about.html',
controller: 'aboutController',
css:'views/css/aboutCustomer.css'
})
});
app.run(['$rootScope', function($rootScope) {
// some post request here
...
$rootScope.$apply(); // trigger digest loop
)};
模板只包含html,但我的控制器执行了两次。
app.controller('aboutController', ['$scope', function($scope) {
console.log('why is executed twice??');
}]);
菜单链接:
<li><a href="#/about/">About</a></li>