angular.js - angular $interval怎么在一个按钮上实现开始定时和结束定时
问题描述
我代码逻辑如下,想要实现:
点击查询按钮,开启定时,按钮文案变成停止查询,
点击停止查询,取消定时
$scope.submitRequest = function () { if ($scope.onlyButton == '查询') { $scope.onlyButton = '停止查询'; $interval(function(){ //具体方法},5000); } else{ setTimeout(function(){ $scope.onlyButton = '查询'; $interval.cancel(stop); },0)}; }
但是没有成功取消定时,求帮忙...
问题解答
回答1:
LZ的代码完全可以在外面做一个 状态标示, 例如:
var interval;$scope.startStatus = false;$scope.submitRequest = function(){ if( !$scope.startStatus ){interval = $interval(...); } else {$interval.cancel(interval); }$scope.startStatus = !$scope.startStatus; }
然后在VIEW中直接类似使用:
<button ng-bind=' !startStatus ? ’查询’ : ’停止查询’ '></button>
我觉得这样写好些~
相关文章:
1. java - Netty服务器端如何检测到客户端网络异常断网??2. css3 - 没明白盒子的height随width的变化这段css是怎样实现的?3. javascript - vue-cli项目中,子组件是否能动态更改路由中的meta属性?4. node.js - 我是一个做前端的,求教如何学习vue,node等js引擎?5. 存储过程 - Mysql时间参数 问题6. PHP类属性声明?7. linux - python 安装 Anaconda 环境变量问题请教8. PHP怎么升级?升级会导致老的网站程序不能用吗?9. javascript - input 怎么获取自动填充的值10. python - 请问django的orm能否独立拿出来使用?例如在非web程序中使用

网公网安备