我注意到只要底层 $scope 变量发生变化,就会自动调用方法。
$scope.getLength = function() {
return $scope.length;
}
我的 html 如下所示
<div class="test">{{getLength}}</div>
每当我更改 $scope.length 时,该方法都会更新 UI 上的值。我知道变量会因为 Angular 中的 MVVM 绑定(bind)而更新。为什么要调用方法?
最佳答案
这种情况也是一种绑定(bind);只是一个函数的绑定(bind)。 AngularJS 每当经历摘要循环时都会更新所有绑定(bind)元素。
关于javascript - Angularjs - 为底层变量自动调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21435613/