首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >$debounce遇到错误

$debounce遇到错误
EN

Stack Overflow用户
提问于 2014-01-08 19:03:48
回答 1查看 410关注 0票数 0

在我的控制器中注入$debounce时,我遇到了这个错误:未知的提供者:$debounceProvider <- $debounce

代码语言:javascript
复制
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;
       };
}]);
EN

回答 1

Stack Overflow用户

发布于 2015-08-26 03:48:27

本地debounce语法是视图的一部分,而不是控制器的一部分:

代码语言:javascript
复制
ng-model-options="{ debounce: 1000 }"

因为它的实现是:

在angular 1.3中使用ng-

-options原生支持模型去抖动

来源如下:

代码语言:javascript
复制
$$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(); 
      });
    }
  }

参考

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20993748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档