Pau*_*nko 6 html javascript templates angularjs
如何在$ scope对象中触发自动变量?
//controller
setInterval(function(){$scope.rand=Math.random(10)},1000);
//template
{{rand}}
Run Code Online (Sandbox Code Playgroud)
Rand在我的页面上没有更新.如何更新我的变量?
Yos*_*shi 10
function MyCtrl($scope, $timeout) {
$scope.rand = 0;
(function update() {
$timeout(update, 1000);
$scope.rand = Math.random() * 10;
}());
}
Run Code Online (Sandbox Code Playgroud)
实际上,最直接的方式是:
function MyCtrl($scope, $interval) {
$scope.rand = 0;
function update() {
$scope.rand = Math.random() * 10;
}
$interval(update, 1000);
}
Run Code Online (Sandbox Code Playgroud)
这是setInterval()的Angular等价物
| 归档时间: |
|
| 查看次数: |
8964 次 |
| 最近记录: |