I have 2 states with ui-router declared like so:
.state('news', {
url: '/news',
views: {
'': {
templateUrl: '/partials/common/news/list.html',
controller: 'NewsIndexController as news'
}
}
})
.state('newsShow', {
url: '/news/:slug',
views: {
'': {
templateUrl: '/partials/common/news/show.html',
controller: 'NewsShowController as newsShow'
}
}
})
My nav bar only has a single news
link in:
<nav>
<ul>
<li>
<a href="/news" ui-sref-active="active">News</a>
</li>
</ul>
</nav>
When I'm on an individual news page, how can I get the news link in the nav to have the active state?
You can use ng-class
:
ng-class="{selected: $state.includes(state)}"
More on $state.includes
here: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state
Hope this will help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.