【发布时间】:2013-01-21 16:25:58
【问题描述】:
模块路由:
var switchModule = angular.module('switchModule', []);
switchModule.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/build-content', {templateUrl: 'build-content.html', controller: BuildInfoController});
}]);
控制器:
function BuildInfoController($http, $scope){
alert("hello");
}
HTML:
<html ng-app="switchModule">
...
<body>
<ul>
<li><a href="#build-content"/></a></li>
</ul>
<div class="ng-view"></div>
</body>
...
每次单击超链接“”时,“BuildInfoController”都会被调用两次。我在这里错过了什么吗?
【问题讨论】:
-
build-content.html 有 `ng-controller="BuildInfoController" 吗?如果是这样,请尝试删除它。
-
没有像你说的那样的 ng-controller。无论如何,非常感谢。我已经使用 camus 的解决方案修复了它。
-
我遇到了类似的问题,但在我的情况下,控制器仅在页面刷新时被触发。如果我从链接导航到页面,控制器只会触发一次,正如预期的那样。但是,如果我刷新页面,它会触发两次。有什么建议吗?
标签: controller angularjs