爲什麼納克級不與工作範圍VAR的Angularjs ngClass工作不正確或他的工作方式?
sheikContolls.controller('MainPageController', ['$scope', 'authService',
function ($scope, authService) {
if(!authService.isAuthenticated()){
$scope.class1 = "good";
}
else {
$scope.class1= "bad";
}
}
]);
HTML:
<div class="demo" ng-class="class1"></div>
當你第一次啓動類添加和我們班=「演示好」,但如果再isAuthenticated()返回true,類不改變,爲什麼? 相同的下一個HTML:
<div class="demo {{class1}}"></div>
如果我做了一個功能 - 所有的工作都很完美。
<div class="demo" ng-class="getClass()"></div>
您必須有[某種指令('ng-if,ng-repeat等......')創建一個子作用域](http://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical- inheritance-in-angularjs)包裝這個div。 – PSL
你能告訴我們'getClass'嗎? –