0

コントローラーに $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;
       };
}]);
4

1 に答える 1

0

ネイティブdebounce構文は、コントローラーではなくビューの一部です。

ng-model-options="{ debounce: 1000 }"

実装は次のとおりです。

debounce は、ng-model-options を使用して angular 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(); 
      });
    }
  }

参考文献

于 2015-08-25T19:48:26.503 に答える