所有
当我在函数中更改$ scope变量时,我想知道何时可以触发数据摘要和更新视图?
说我有类似的功能:
var app = angular.module("app", []);
app.controller("main", function($scope) {
$scope.data1 = "old data 1";
$scope.data2 = "old data 2";
function changedata() {
this.data1 = "new data 1";
for (var i = 0; i < 1000; i++) {
for (var j = 0; j < 1000; j++) {
for (var k = 0; k < 2000; k++) {
var data = i * j * k;
}
}
}
this.data2 = "new data 2";
}
$scope.changedata = changedata.bind($scope);
})
&#13;
<html ng-app="app">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-controller="main">
<button ng-click="changedata()">Change data(click and wait a little bit time)</button>
<div>{{data1}}</div>
<div>{{data2}}</div>
<div>I change data 1 first, then set a blocking delay and change data2 in the click handler, I wonder how can I make angular update the view immediately after data 1 changed rather than waiting for the function call finished? In another way, at what point does angular digest cycle get triggered?
</body>
</html>
&#13;
当我点击按钮时,视图中的data1永远不会更新,直到函数返回,我想知道Angular是否根据函数调用摘要数据和更新视图? 如果没有,任何人都可以提供一些细节角度检查数据如何变脏并运行更新?
由于