Hi
I have below code . I want when user Clicks on Add Modal popup should open which has been defined in a Child component.
Dynamic Table is a separate component
Code
addCode
Product Form
-->
-->
Product Name
This is required
Minimum length is 4
-->
Product Description
Product Image
Cancel
Save
-->Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted Jul 9, 2024, 3:39 AM EDT
From your code, it seems like you’re missing the click event handler on the “Add” button that should trigger the modal to open. You need to add a
(click)event to the button that will call theopenDialogfunction.Here’s how you can do it:
In your TypeScript file, you should have a method
openDialogthat opens the modal. If you’re using Angular Material, you can use theMatDialogservice to open the modal. Here’s an example:import { MatDialog } from '@angular/material/dialog'; // import your dialog component import { DialogComponent } from './dialog.component'; constructor(private dialog: MatDialog) { } openDialog(event: Event) { const dialogRef = this.dialog.open(DialogComponent); dialogRef.afterClosed().subscribe(result => { console.log(`Dialog result: ${result}`); }); }In this example,
DialogComponentis the component that contains your form. You would replace this with the component that contains your form.Remember to import
MatDialogModulein your module file.Thanks