角度和去抖動在AngularJS中,我可以使用ng-model選項去抖模型。ng-model-options="{ debounce: 1000 }"如何在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 controllerclass 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);而我的HTML<input type=text [value]="firstName" #first (keyup)="firstNameChanged($event, first)">但是我正在尋找一個內置函數,Angular中有一個嗎?
角度和去抖動
紅顏莎娜
2019-08-12 10:45:05