在我的控制器中注入$debounce时,我遇到了这个错误:未知的提供者:$debounceProvider <- $debounce
myControllers.controller('Controller',
['$scope', '$compile', '$rootScope', '$timeout', '$document', '$debounce','promiseTracker',
function ($scope, $compile, $rootScope, $timeout, $document,$debounce, promiseTracker) {
$scope.$watch('newquery', function (newValue, oldValue) {
if (newValue === oldValue) { return; }
$debounce(applyQuery, 350);
});
var applyQuery = function () {
$scope.filter.query = $scope.query;
};
}]);发布于 2015-08-26 03:48:27
本地debounce语法是视图的一部分,而不是控制器的一部分:
ng-model-options="{ debounce: 1000 }"因为它的实现是:
在angular 1.3中使用ng-
-options原生支持模型去抖动
来源如下:
$$debounceViewValueCommit: function(trigger)
{
var debounceDelay = this.$options.getOption('debounce');
if (isNumber(debounceDelay[trigger]) )
{
debounceDelay = debounceDelay[trigger];
}
else if (isNumber(debounceDelay['default']) )
{
debounceDelay = debounceDelay['default'];
}
this.$$timeout.cancel(this.$$pendingDebounce);
var that = this;
if (debounceDelay)
{
this.$$pendingDebounce = this.$$timeout(function() {
that.$commitViewValue();
}, debounceDelay);
}
else if (this.$$scope.$root.$$phase)
{
this.$commitViewValue();
}
else
{
this.$$scope.$apply(function() {
that.$commitViewValue();
});
}
}参考
https://stackoverflow.com/questions/20993748
复制相似问题