AngularJS 监听变量变化的实现方法
来源:动视网
责编:小采
时间:2020-11-27 22:06:25
AngularJS 监听变量变化的实现方法
AngularJS 监听变量变化的实现方法:如下所示: var timeout; $scope.$watch('search.subj',function (newVal, oldVal) { if (newVal !== oldVal) { if (timeout) $timeout.cancel(timeout); timeout = $timeout(function() { $scop
导读AngularJS 监听变量变化的实现方法:如下所示: var timeout; $scope.$watch('search.subj',function (newVal, oldVal) { if (newVal !== oldVal) { if (timeout) $timeout.cancel(timeout); timeout = $timeout(function() { $scop

如下所示:
var timeout;
$scope.$watch('search.subj',function (newVal, oldVal) {
if (newVal !== oldVal) {
if (timeout) $timeout.cancel(timeout);
timeout = $timeout(function() {
$scope.doSearch();
}, 800);
}
}, true);
以上这篇AngularJS 监听变量变化的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
AngularJS 监听变量变化的实现方法
AngularJS 监听变量变化的实现方法:如下所示: var timeout; $scope.$watch('search.subj',function (newVal, oldVal) { if (newVal !== oldVal) { if (timeout) $timeout.cancel(timeout); timeout = $timeout(function() { $scop