简体   繁体   English

AngularJS指令ngClass不起作用?

[英]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. 我正在使用此Angulars代码。 Finally I find the expression {{ isActive === 'main' }} is true,but the className 'active' is not updated 最后我发现表达式{{isActive ==='main'}}为true,但className'active'未更新

Your code should be working: JSFiddle : 你的代码应该正常工作: 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 . 最有可能是ng-controller

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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