我試圖設置當前選項卡上的活動鏈接 像angularjs UI路由器設置爲活動鏈接不起作用
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'));
})
給我的真實。
你知道有什麼問題嗎?
'$ state'是否可以在'$ scope'這個位置使用? –
我以爲同樣的事情(但它很奇怪,因爲最佳實踐說腳本接近