相关疑难解决方法(0)

角度和去抖动

在AngularJS中,我可以使用ng-model选项去抖模型.

ng-model-options="{ debounce: 1000 }"
Run Code Online (Sandbox Code Playgroud)

如何在Angular中去抖模型?我试图在文档中搜索debounce,但我找不到任何东西.

https://angular.io/search/#stq=debounce&stp=1

一个解决方案是编写我自己的去抖函数,例如:

import {Component, Template, bootstrap} from 'angular2/angular2';

// Annotation section
@Component({
  selector: 'my-app'
})
@Template({
  url: 'app.html'
})
// Component controller
class MyAppComponent {
  constructor() {
    this.firstName = 'Name';
  }

  changed($event, el){
    console.log("changes", this.name, el.value);
    this.name = el.value;
  }

  firstNameChanged($event, first){
    if (this.timeoutId) window.clearTimeout(this.timeoutID);
    this.timeoutID = window.setTimeout(() => {
        this.firstName = first.value;
    }, 250)
  }

}
bootstrap(MyAppComponent);
Run Code Online (Sandbox Code Playgroud)

而我的HTML

<input type=text [value]="firstName" #first (keyup)="firstNameChanged($event, first)">
Run Code Online (Sandbox Code Playgroud)

但是我正在寻找一个内置函数,Angular中有一个吗?

javascript angular

145
推荐指数
8
解决办法
14万
查看次数

标签 统计

angular ×1

javascript ×1