我正在使用角度 8。有一個自動完成輸入,如果它的值發生變化,我必須進行 API 調用并為此輸入加載新建議。 //In Template <autocomplate [suggestions]="suggestions" (filterChange)="filterChange($event)"></autocomplate> //In Component filterChange(e) { console.log(e) this.loadSubscriptions(e ? { 'filterItem.name': e } : {}) } loadSubscriptions(params) { if (this.suggestionsSubscriber) this.suggestionsSubscriber.unsubscribe() this.suggestionsSubscriber = this.suggestionsService.loadData(params).subscribe( data => this.suggestions = data }) }一切正常,但問題是當用戶鍵入快速應用程序對許多請求時。如果用戶輸入速度快,我可以以某種方式延遲請求嗎?例如,當用戶輸入時,不要在每次更改時都調用 API,如果用戶停止輸入,則調用 API?;蛘呷绻阌懈玫姆椒▉斫鉀Q這個問題,請分享。
Angular,對輸入“變化時”的許多 API 調用
素胚勾勒不出你
2021-08-20 16:20:49