"材质"对话框"角度"



我正在创建一个Dialog,当我选择一个值时,它将填充到input fields,但现在我正试图在FormArray中创建一个在我选择true时显示的hidden button,但如果我选择了False,它不会显示隐藏按钮是如何实现的?

以下是我到目前为止所做的

https://stackblitz.com/edit/mat-dialog-example-wvsgaj

我已经分叉了您的样本。看看这个。https://stackblitz.com/edit/mat-dialog-example-gheonh

item中添加了showButton属性。

item(): FormGroup {
return this.fb.group({
qty: [10],
total: [],
showButton: false, // here
});
}

然后在afterClosed中设置此属性。

dialogRef.afterClosed().subscribe((result) => {
const showButton = result.symbol;
(this.fg.get('Info') as FormArray)
.at(index)
.get('showButton')
?.patchValue(showButton);
});

在html中,使用该值切换显示或隐藏。

<button
mat-raised-button
color="primary"
class="row"
*ngIf="Info.get('showButton').value"
>
TriggerButton
</button>

最新更新