我在js中使用超时功能:
setTimeout(function () {
$scope.shadow = 'speller-blue';
currIndex = Math.floor(Math.random() * 2);
$scope.currCard = cards[currIndex];
}, 1000);
我在我的html中使用ng-class:
<input id="speller-box" type="text" class="form-control ng-class:shadow" autofocus="" placeholder="answer" ng-model="answer">
我希望超时中的代码在一秒钟延迟后执行并将字段变为蓝色,但直到输入框中的值发生更改才会发生更改。
答案 0 :(得分:1)
Angular不会知道setTimeout
改变了什么,直到它完成下一个消化周期。在对范围进行更改后,可以使用$timeout
或手动调用$digest
。
答案 1 :(得分:0)
我认为你做错的一件事是你正在应用条件类,但你使用的格式不正确
执行类似
的操作<input id="speller-box" type="text" ng-class="{'form-control': shadow}" autofocus="" placeholder="answer" ng-model="answer">