gpt4 book ai didi

angular - 以 Angular Material 调用 Dialog 组件内的组件

转载 作者:行者123 更新时间:2023-12-04 01:26:03 25 4
gpt4 key购买 nike

我有 2 个组件称为
1) demo2) add-customer
demo组件我有一个 按钮 称为添加。单击按钮时,会调用一个函数(例如 openDialog() )来打开 对话 window(i,e op-up window)。现在我想调用add-customer这个里面的组件对话 window 。
我怎样才能做到这一点。这里是 stackblitz关联。

最佳答案

Demo.component.ts 您需要将组件“插入”到对话框中。

import {AddCustomerComponent} from '../add-customer/add-customer.component'

openDialog(): void {
const dialogRef = this.dialog.open(AddCustomerComponent, {
width: '450px',
});

app.module.ts,将对话框中加载的组件添加到entryComponents
declarations: [
AppComponent,
DemoComponent,
AddCustomerComponent,
],
entryComponents: [
AddCustomerComponent
],

编辑:要关闭取消,您必须在 add-customer.component.html 上的取消按钮上添加一个单击功能
<button mat-raised-button type="button" class="Discard-btn" (click)="cancel()">Cancel</button>

然后在 .ts 文件中添加函数并在构造函数中注入(inject) dialogRef
import {MatDialogRef} from '@angular/material';

constructor(private fb: FormBuilder,
private dialogRef: MatDialogRef<AddCustomerComponent>) {}

public cancel() {
this.dialogRef.close();
}

关于angular - 以 Angular Material 调用 Dialog 组件内的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52551861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com