Reputation: 61
Suppose I have component with
@Input() timeData: TimeData
where TimeData
contains only one field: time
.
I want to observe timeData.time
, assuming that only timeData.time
was changed (not the whole timeData
)
ngOnChanges
doesn't track such change, while {{timeData.time}}
works perfect.
My final goal is to set flag goodTime
if(timeData.time % 10 === 0){
goodTime = true
}
Upvotes: 1
Views: 1090
Reputation: 61
I did't noticed that before, but someone else also posed similar question:
How to get onChanges for properties changed on an object sent in for an @Input
Upvotes: 0
Reputation: 657068
You don't provide information about how your TimeData
looks like but when you add an EventEmitter
you can subcribe to changes.
class TimeData {
_time: number;
get time(): number {
return this._time;
}
set time(value: number) {
this._time = number;
timeChange.next(number);
}
timeChange: EventEmitter<number> = new EventEmitter<number>();
}
use it like
timeData.timeChange.subscribe((value) => { doSomething(value);}
Upvotes: 5