我是 angularJS 的初级初学者,我正在使用 node/bower/grunt 为 angularJS 中的单页应用程序开发 ui,我已经安装了 angular-ui-bootstrap 以及来自 angular-ui 的路由和事件实用程序-实用程序。
I've used ng-class={active:$uiRoute}
on the menu items but when a menu item is selected the active class is not applied...does $uiRoute
处理这个还是我需要单独编码?
抱歉问了一个愚蠢的问题...
这是代码:
`<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li ui-route="/" ng-class="{active:$uiRoute}"><a href="#/">Home</a></li>
<li ui-route="/about" ng-class="{active:$uiRoute}"><a href="#/about">About</a></li>
<li ui-route="/other" ng-class="{active:$uiRoute}"><a href="#/other">Other</a></li>
</ul>
</div>
...
<script src="bower_components/angular-ui-utils/modules/route/route.js"></script>
<script src="bower_components/angular-ui-utils/modules/event/event.js"></script>`
和
angular.module('myApp', ['ngRoute','ngResource','ui.bootstrap'])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/other', {
templateUrl: 'views/other.html',
controller: 'OtherCtrl'
})
.otherwise({
redirectTo: '/'
});
})
最佳答案
浏览ui-utils docs ,看来您还没有注入(inject)模块依赖项。更改您的 myApp
以注入(inject) ui.utils
angular.module('myApp', [
'ngRoute',
'ngResource',
'ui.bootstrap',
'ui.utils'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/other', {
templateUrl: 'views/other.html',
controller: 'OtherCtrl'
})
.otherwise({
redirectTo: '/'
});
});
关于javascript - 如何使用 angular-ui-utils 将事件类应用于导航栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19992236/