我有 2 個組件:父母和孩子。我希望子組件出現在模式框中。請問我該怎么做?
uj5u.com熱心網友回復:
如果你查看 Angular Material 的對話框組件,你可以將一個組件傳遞給它的 MatDialog 服務。您需要做的就是在父組件建構式中注入 MatDialog 并將帶有子組件的對話框的打開附加到您想要的任何事件(根據我的理解,單擊按鈕)!
@NgModule({
declarations: [
ParentComponent,
ChildComponent,
],
imports: [
MatDialogModule
]
})
export class ExampleModule { }
@Component({
selector: 'parent-component',
template: `
<button (click)="openDialog()"></button>
`
})
export class ParentComponent {
constructor(private dialog: MatDialog) {}
openDialog() {
this.dialog.open(ChildComponent);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/479659.html
上一篇:行為主體回傳null
