angular.js - How to change the button style after angular routing?
高洛峰
高洛峰 2017-05-15 17:11:10
0
2
616

As mentioned, I want to change the style of the button after routing, that is, after clicking the about link, the active class should disappear from the API and be transferred to about.

But I don’t want to implement it through dom (it feels like I’m still using jquery to solve the problem). May I ask how to achieve elegance in Angular?

<ul class="nav navbar-nav">
     <li class="active"><a href="#/">API</a></li>
     <li><a ng-href="#/about">About</a></li>
</ul>
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
黄舟
$scope.$state = $state;
<ul class="nav navbar-nav">
     <li ng-class="{'active': $state.current.name = 'main'}"><a href="#/">API</a></li>
     <li ng-class="{'active': $state.current.name = 'about'}"><a ng-href="#/about">About</a></li>
</ul>

Replace the route name above with the actual one

You can also use the ui-router command, refer to

黄舟

You can use the ng-class instruction bool to determine, bind the click event and pass the $index of li.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template