AngularJS指令ngClass不起作用?

时间:2016-09-04 07:44:50

标签: javascript angularjs ng-class

<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>

我正在使用此Angulars代码。 最后我发现表达式{{isActive ==='main'}}为true,但className'active'未更新

1 个答案:

答案 0 :(得分:0)

您的代码应该正常运行: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';
}]);

您的代码在其他地方一定有问题。最有可能是ng-controller