There is a simple fix, that is not documented in the docs but I found it in this issue. You just need to split two way binding into one way binding using visbile
and visibleChange
properties like this:
<p-dialog header="My dialog"
[visible]="showDialog$ |async"
(visibleChange)="handleClose()"
>
Above I use Angular's async pipe to show the dialog and handleClose() method to close the dialog. In the .ts
file I can have a service injected which is using some observable of boolean value that is changing based on some condition.
export class HomeComponent implements OnInit {
showDialog$!: Observable<boolean>;
constructor(private homeService: HomeService) { }
ngOnInit(): void {
this.showDialog$ = this.homeService.displayDialog$;
}
handleClose() {
this.homeService.toogleDisplayDialog();
}
}