How to make 2-way data binding for a custom input in child component in Angular 8?
I used banana-in-a-box [(...)]
syntax but it doesn't make changes in child component visible in the parent component.
In the result, it should work with the banana-in-a-box syntax.
parent.component.ts
...
public childVisibility: boolean = true;
...
parent.component.html
childVisibility : {{childVisibility}}
<app-child-component [(visible)]="childVisibility">
</app-child-component>
child.component.ts
@Component({
selector: 'app-child-component',
templateUrl: './app-child.component.html',
styleUrls: ['./global-search-results.component.scss']
})
export class ChildComponent {
@Input() visible: boolean;
constructor() {}
public changeVisible() {
this.visible = false;
}
}
child.component.html
<button (click)="changeVisible()">
Change Visible
</button>