Angular on-change multiple calls removal(debounce/timers/time manipulation?)
<p>I have a situation where I can't use debounce in html like <code>ng-model-option: {debounce:1000}</code></p>

<p>But I want to remove repeated callbacks to function doCallback in my directive, and make only 1 call in 1s</p>

<p>html: <code>&lt;input ng-change="vm.GetStuff"&gt;</code></p>

<p>angular directive:</p>

<pre><code>class SuperDirective {
    eventTime: any;
    anotherCallWasMade: boolean;

  static $inject = ['$scope', "$timeout"];
  constructor($scope: angular.IScope, $timeout: ng.ITimeoutService) {
            super();
...
      }



   GetStuff(): void {

          //I've tried something like this but it didn't exactly work             
          if (this.eventTime == undefined) {
                this.eventTime = Date.now();
                this.anotherCallWasMade = true;
            } else {
                var currentTime = Date.now().valueOf();
                var eventTime = this.eventTime.valueOf();
                var sec = (Date.now().valueOf() - this.eventTime.valueOf())/1000;
                if (sec &lt;= 1) {
                //If this is the first attempt after original request then we perform a search once more, if this is another request during the same second we dont do anything..
                    if (this.anotherCallWasMade) {
                        this.anotherCallWasMade = false;
                        this.$timeout(() =&gt; {
                            this.eventTime = Date.now();
                            this.get_Items();
                        }, 1000);
                    }
                    return;
                }
                this.anotherCallWasMade = true;
                this.eventTime = Date.now();
            }

                this.$timeout(() =&gt; {
                    if (this.doCallback != null) {
                        // I want to call this once in 1s instead of multiple times 
                        this.doCallback ();
                    }
                }, 0);

            }
        }
</code></pre>

<p>maybe there is an easier way to remove unnessesary calls to this.doCallback() ? </p>