在我的控制器中注入$ 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;
};
}]);
答案 0 :(得分:0)
本机debounce
语法是视图的一部分而不是控制器:
ng-model-options="{ debounce: 1000 }"
因为实施是:
使用ng-model-options
在角度1.3中本机支持去抖动
来源如下:
$$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();
});
}
}
<强>参考强>