1
<ul class="ul_nav">
<li ng-class="class" ng-click="changeClass()">Marketing</li>
<li ng-class="class" ng-click="changeClass()">Sells Team Nestle</li>
<li ng-class="class" ng-click="changeClass()">Marketing Test</li>
<li ng-class="class" ng-click="changeClass()">Marketing </li>
</ul>
Angularjs
$scope.changeClass = function(){
if ($scope.class === "nav_color")
$scope.class = "nav_active";
else
$scope.class = "nav_color";
};
CSS
.ul_nav{
margin-top:15px;
list-style:none;
padding:0;
height:600px;
}
.ul_nav > li{
padding: 3px 0 3px 25px;
cursor:pointer;
}
.ul_nav > li:hover{
background:#ff9900;
color:#fff;
}
.nav_color{
background:#fff;
color:#000;
}
.nav_active{
background:#ff9900;
color:#fff;
}
在這裏,我可以改變導航的背景顏色。但是當我點擊一個項目時,它會改變所有4項目的背景顏色。如何解決這個問題。 Plunker
你創建一個使用NG-重複這個'li'的..? –