角度和去抖动
在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中有一个吗?
红颜莎娜
一只甜甜圈
随时随地看视频慕课网APP
相关分类