html - angular 跳轉(zhuǎn)頁面時(shí),非ng-view部分的內(nèi)容如何刷新
問題描述
我的頁面上有一個(gè)Menu Bar:
<ul class='nav nav-tabs nav-stacked main-menu'> <li><a href='http://www.leifengta.com.cn/templates/home.html#/'><i class='icon-bar-chart'></i><span class='hidden-tablet'> 高校概覽</span></a></li> <li><a href='http://www.leifengta.com.cn/templates/home.html#/Comments'><i class='icon-envelope'></i><span class='hidden-tablet'> 高校評(píng)論</span></a></li> <li><a href='http://www.leifengta.com.cn/templates/home.html#/Views'><i class='icon-tasks'></i><span class='hidden-tablet'> 校內(nèi)景點(diǎn)</span></a></li></ul>
作為我的頁面導(dǎo)航欄,其余的部分使用ng-view來更新,現(xiàn)在遇到的問題是,我跳轉(zhuǎn)到其他頁面后,Menu Bar并不會(huì)刷新,所以看上去就選擇了很多標(biāo)簽:

謝謝~
問題解答
回答1:我們的做法是監(jiān)聽 routeChangeSuccess 然后 更新 某個(gè)變量path的值
然后在menu那里就判斷 ng-class='{active:path=’xx’}'
回答2:http://stackoverflow.com/a/18562339
回答3:推薦使用angular的一個(gè)比較好的插件ui-router對(duì)于你這種情況,只需要添加一個(gè)ui-sref-active='yourCSSStyle'就可以了,簡(jiǎn)單方便。可以參考:ui-router 以及 ui-sref-active

網(wǎng)公網(wǎng)安備