1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試下面
訂閱
valueChanges
表單的屬性。當(dāng)您對(duì)表單進(jìn)行任何更改時(shí),這將執(zhí)行通過(guò)管道將訂閱傳遞給
debounceTime
運(yùn)算符,這將確保調(diào)用函數(shù)之前有延遲通過(guò)運(yùn)算符管道 Observable
distinctUntilChanged
,我們不想對(duì)相同的值調(diào)用 location
import { combineLatest } from 'rxjs';
import { debounceTime, distinctUntilChanged, tap } from 'rxjs/operators';
latitude$ = this.myform.get('Latitude').valueChanges;
longitude$ = this.myform.get('Longitude').valueChanges;
formChanges$ = combineLatest([this.latitude$, this.longitude$]).pipe(
debounceTime(1000),
distinctUntilChanged(),
tap(() => this.refreshMap())
)
ngOnInit() {
this.formChanges$.subscribe()
}
添加回答
舉報(bào)