I have the following angular components:
ComponentB which has an input property, and componentA which insert componentB in the template file.
The code looks as the following:
componentA.ts:
export class ComponentA{
isOpen: boolean;
methodA() {
this.isOpen = false;
// do some work
}
}
componentA.html:
<componentB [(open)]="isOpen"></componentB >
ComponentB.ts:
@Component({
selector: 'componentB',
templateUrl: 'ComponentB .html',
encapsulation: ViewEncapsulation.None,
})
export class ComponentB {
private _open: boolean = false;
@Input('open') set open(value: boolean) {
if (open === this._open) {
return;
}
if (open) {
// doSomething()
} else {
// doSomethingElse()
}
this._open = open;
}
get open() {
return this._open;
}
}
The issue is that isOpen property doesn't seems to reflect the current value of open property, although two way binding was specified.
Why does it happens? How can it be fixed?