如何在 $scope 对象上自动触发我的变量?
//controller
setInterval(function(){$scope.rand=Math.random(10)},1000);
//template
{{rand}}
兰德在我的页面上没有更新。如何更新我的变量?
最佳答案
function MyCtrl($scope, $timeout) {
$scope.rand = 0;
(function update() {
$timeout(update, 1000);
$scope.rand = Math.random() * 10;
}());
}
关于javascript - Angular JS。在 html 中自动刷新 $scope 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14500602/