Last active
April 29, 2024 19:30
-
-
Save andrewarosario/91be760f39590660dfec257306dcea6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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