I have two @Input props, and I want to monitor one of them, and do something everytime it changes.
However, this "do something" is dependent on another @Input.
For example
// This is the 1st input prop, which is monitored using a setter
private _inputOne: string;
@Input() set inputOne(value: string) {
this._inputOne= value;
// Whether the setter needs to do something depends on another input called "inputTwo"
if (this.inputTwo) {
... do something
}
}
get _inputOne(): string {
return this._inputOne;
}
// This is the 2nd input prop.
@Input() inputTwo: boolean;
The problem is that, the setter set inputOne(value: string) seems to have no access to the other input inputTwo. From its POV, inputTwo is always undefined, but it really needs its actual value.
I am wondering how to solve this issue...
Maybe I can pass in both of them from the parent component everytime only inputOne is changed, then use the ngOnChanges hook, because it has access to both of them, but is there a more elegant solution?
Thanks in advance!