In my Angular app I have a home (parent) component that I’m displaying a modal in:
<button>
New message
</button>
<app-modal modalTitle="New message">
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nam nihil
dignissimos cumque provident eius id magnam blanditiis saepe. Reiciendis
inventore nihil modi eveniet laborum quidem quo labore minima porro?
Laudantium.
</p>
<div modalFooter>
<button>Custom button</button>
</div>
</app-modal>
The modal component is:
<dialog #modal class="max-w-screen-xl border rounded-t-lg">
<button (click)="modal.close()">
rest of markup....
</dialog>
When clicking the New message
button in the parent component, I want to call the openModal()
method on the <dialog>
element in the modal component.
I have tried using an EventEmitter
and Output
but it didn’t work.
What is the common way to do something like this in Angular?
2
Answers
I guess one of approaches is:
In your parent component.ts:
In your parent component.html:
In your modal component.ts:
In your modal component.html:
I have done native HTML dialogs in Angular apps for a bit. My approach is usually something like this:
my-component.html
my-component.ts