AngularJS视图不更新的模式变革 [英] AngularJS view not updating on model change
本文介绍了AngularJS视图不更新的模式变革的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出如何角的作品和我有麻烦我的看法更新时模型的变化。
i'm trying to figure out how Angular works and am having trouble getting my view to update when the model changes..
HTML
<div ng-app="test">
<p ng-controller="TestCtrl">
{{testValue}}
</p>
</div>
JS
var app = angular.module('test', []);
app.controller('TestCtrl', function ($scope) {
$scope.testValue = 0;
setInterval(function() {
console.log($scope.testValue++);
}, 500);
});
什么想法?
推荐答案
由于阿贾伊beniwal上面提到你需要使用应用开始消化。
As Ajay beniwal mentioned above you need to use Apply to start digestion.
var app = angular.module('test', []);
app.controller('TestCtrl', function ($scope) {
$scope.testValue = 0;
setInterval(function() {
console.log($scope.testValue++);
$scope.$apply()
}, 500);
});
这篇关于AngularJS视图不更新的模式变革的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文