简体   繁体   中英

The AngularJS directive ngClass is not working?

 <a href="#/main" class="bottom-nav-btn"> <img ng-src="dist/images/toolbar1.png" alt="首页" class="nav-img" /> <p class="nav-text" ng-class="{active: isActive==='main'}">首页</p> <p>{{ isActive === 'main' }}</p> </a> 

I am using this Angulars code. Finally I find the expression {{ isActive === 'main' }} is true,but the className 'active' is not updated

Your code should be working: JSFiddle :

<a href="#/main" class="bottom-nav-btn" ng-app="Joy" ng-controller="JoyCtrl">

angular.module('Joy', [])
.controller('JoyCtrl', ['$scope', function($scope) {
    $scope.isActive = 'main';
}]);

There must be something wrong with your code in other place. Most likely to be the ng-controller .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM