我的 index.html 页面中有一个带有导航栏的 angularjs 应用程序,如下所示:
<div class="navbar navbar-inverse navbar-fixed-top" ng-controller="NavCtrl">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li>
<a href="#/">Home</a>
</li>
<li>
<a href="#/add">Add a contact</a>
</li>
<li>
<a href="#/users">Users</a>
</li>
<li>
<a href="#/agencies">Agencies</a>
</li>
<li>
<a ng-click="intro()">Help</a>
</li>
</ul>
</div>
</div>
</div>
这个 div 使用一个控制器,当我点击帮助链接时,它会调用我的控制器的 intro 方法。但是这个方法每次调用两次!!
这是我的控制器:
'use strict';
angular.module('myApp')
.controller('NavCtrl', function ($scope, $location) {
$scope.intro = function(){
if($location.path() != '/'){
toastr.warning("Warning.");
}else{
introJs().start();
}
}
});
任何想法 ?..
这是完整的 html :
<div class="navbar navbar-inverse navbar-fixed-top" ng-controller="NavCtrl">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li ng-class="navClass('')">
<a href="#/">Home</a>
</li>
<li ng-class="navClass('add')">
<a href="#/add">Add a contact</a>
</li>
<li ng-class="navClass('users')">
<a href="#/users">Users</a>
</li>
<li ng-class="navClass('agencies')">
<a href="#/agencies">Agencies</a>
</li>
<li>
<a ng-click="intro()">Help</a>
</li>
</ul>
</div>
</div>
</div>
<div class="show-grid"></div>
<div class="container">
<div class="row" ng-view></div>
</div>