I have declared the following variable:
public filter: IFilterWeekScheduleClassShort = {};
How to subscribe on changes(listen object filter)?
I tried this:
private filter: IFilterWeekScheduleClassShort = {};
private filterChanges: BehaviorSubject<IFilterWeekScheduleClassShort> = new BehaviorSubject(this.filter);
this.filterChanges.subscribe((model) => {
console.log(model);
});
Is it okay?
My final code:
public _filter: IFilterWeekScheduleClassShort = {};
private filterChanges: BehaviorSubject<IFilterWeekScheduleClassShort> = new BehaviorSubject(this._filter);
this.filter = {a: 1, b: 2}
set filter(value: any) {
this._filter = value;
this.filterChanges.next(this._filter);
}
get filter() {
return this.filterChanges.asObservable();
}
Subscribe on:
this.filter.subscribe(model => {
console.log(model);
});
Changes I make from form:
[(ngModel)]="_filter.teacherId"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With