我有这个指令,它使用服务“BoxService”来获取某个值。
angular.module("App").directive('boxedWidget',
function () {
return {
restrict: 'E',
scope: {
'source': '=',
},
replace:true,
templateUrl: '/widgets/box/widget.html',
link: function (scope, element, attrs) {
scope.item = scope.source;
boxService
.getBoxeValue(scope.item.id)
.success(function(data, status, headers, config) {
scope.item.value = data;
});
}
}
});
现在我想每 5 秒刷新一次该值。 有什么建议吗?
最佳答案
您可以尝试$interval
在指令中重新加载数据
$interval(function () {
loadData();
}, duration)
关于$interval
的更多详情可以引用 Angular $interval
关于javascript - 刷新 Angular 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35357907/