我正在尝试设置一个活动链接在当前选项卡上,例如
in jade
ul.nav.navbar-nav
li(ng-class="{ active: $state.includes('index') }")
a(ui-sref='index') Home
li(ng-class="{ active: $state.includes('post') }")
a(ui-sref='post') Post
html
<li ng-class="{ active: $state.includes('index') }"><a ui-sref="index" href="#/">Home</a></li>
<li ng-class="{ active: $state.includes('post') }"><a ui-sref="post" href="#/post">Post</a></li>
js .config(function($stateProvider,RestangularProvider,PostProvider,PostsProvider,MediaProvider) {
$stateProvider
.state('index', {
url: '/',
templateUrl: 'admin/views/index.html',
controller: 'HomeCtrl'
})
.state('post', {
url: '/post',
templateUrl: 'admin/views/post/index.html',
resolve: {
posts: function(Posts){
return Posts.all();
}
},
controller: 'PostIndexCtrl'
})
但行不通。但是,如果我尝试检查它:
.controller('PostIndexCtrl', function ($scope,posts,$state) {
$scope.posts = posts;
console.log($state.includes('post'));
})
给我真实。
你知道有什么问题吗?
.run(function ($state,$rootScope, $log) {
$rootScope.$state = $state;
});
如果要访问它,则需要将$状态放在$ rootscope上。非常感谢UI-Router的人:)