Answer the question
In order to leave comments, you need to log in
How to change the @input property in the component so that the binding is not lost?
I have a component like this:
<div class="a">
<div class="b" *ngIf="shown">blabla</div>
<button (click)="onClick()">test</button>
</div>
@Component({
selector: 'my-component'
})
export class MyComponent {
@Input
shown: boolean;
onClick():void {
this.shown = false;
}
}
<my-component [shown]="property"></my-component>
Answer the question
In order to leave comments, you need to log in
You need to do a two-way link.
@Component({
selector: 'my-component'
})
export class MyComponent {
@Input()
shown: boolean;
@Output()
shownChange = new EventEmitter<boolean>();
onClick():void {
this.shown = false;
this.shownChange.emit(this.shown);
}
}
<my-component [(shown)]="property"></my-component>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question