Skip to content

Instantly share code, notes, and snippets.

@andrewarosario
Last active April 29, 2024 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewarosario/91be760f39590660dfec257306dcea6c to your computer and use it in GitHub Desktop.
Save andrewarosario/91be760f39590660dfec257306dcea6c to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-modal',
template: `
<button
[routerLink]="[]"
[queryParams]="{isOpen: true}">
Abrir Modal
</button>
<nz-modal
[nzVisible]="isOpen$ | async"
nzTitle="Minha Modal"
(nzOnCancel)="closeModal()"
(nzOnOk)="closeModal()">
<ng-container *nzModalContent>
<p>Conteúdo do modal</p>
</ng-container>
</nz-modal>
`,
})
export class ModalComponent implements OnInit {
isOpen$: Observable<boolean>;
private activatedRoute = inject(ActivatedRoute);
private router = inject(Router);
ngOnInit(): void {
this.isOpen$ = this.activatedRoute.queryParams.pipe(
map(({ isOpen }) => isOpen === 'true')
);
}
closeModal(): void {
this.router.navigate([], { queryParams: { isOpen: false } });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment