javascript - 将变量作为参数传递给 angularjs 中的 setInterval 函数
问题描述
我需要将一个变量传递给setInterval
angularjs 并在间隔后返回给另一个函数
例子:
$scope.start = function(host_id) {
// store the interval promise
$scope[`promise_${host_id}`] = $interval(function(host_id){
$scope.update_status(host_id)
}, 3000);
};
// stops the interval
$scope.stop = function(host_id) {
$interval.cancel($scope[`promise_${host_id}`]);
};
$scope.start(5);
解决方案
推荐阅读
- ios - 在苹果商店添加评论信息截图?
- wordpress - Elementor 小部件分离问题
- python - “!”是什么意思?在python中登录吗?或者它是一个Linux commad?
- javascript - MongoDB:你可以将一个集合作为一个字段包含在另一个集合的文档中吗?
- angular - 无法在 ngForm 中初始化 ng-select
- javascript - 在 react 中使用 map 列出 JSON 的所有值时遇到问题
- x86 - 是否可以通过提供更早的提示来减轻分支错误预测的惩罚?
- android - 如何使用 DiffUtil 保存对旧列表的引用
- python-3.x - 运行 Azure DevOps 管道存在 ##[error]Bash exited with code '1'
- c# - 在 WPF Prism MVVM 中,如何从子视图调整父视图的大小