如果值為 ,是否有某種原因,為什么[mat-dialog-close]="createFurtherCheckbox.checked ? 'false' : 'true'"不起作用?在一個對話框中,我通過單擊提交按鈕創建一個物件,如果選中某個復選框,這會質疑我是否要創建另一個物件,對話框不會關閉,所以我可以創建另一個物件(在這種情況下是一個課程) . 如果選中復選框,我希望對話框重置并保持打開狀態。[mat-dialog-close]false
即使我嘗試[mat-dialog-close]="false"關閉對話框。
但是[type]="createAnotherCheckbox.checked ? 'reset' : 'button'",“重置”型別是否正確更改。(用于重置表單內的 formControls)
創建課程dialog.component.html
<mat-dialog-actions>
<mat-checkbox #createFurtherCheckbox>Create another course?</mat-checkbox>
<button mat-raised-button [mat-dialog-close]="createFurtherCheckbox.checked ? 'false' : 'true'" [type]="createFurtherCheckbox.checked ? 'reset' : 'button'"
(click)="Submit()" [disabled]="courseForm.invalid">Create course</button>
<button mat-raised-button mat-dialog-close>Cancel</button>
</mat-dialog-actions>
uj5u.com熱心網友回復:
我認為您誤解了mat-dialog-close 指令的輸入。
@Input('mat-dialog-close')
dialogResult: any
您正在為訂閱 afterClosed 時獲得的結果設定回傳值,如下所示
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
使用 ngif 和兩個按鈕的快速解決方法
<ng-container *ngIf="createAnotherCheckbox.checked">
<button mat-raised-button type="reset" (click)="Submit()" [disabled]="courseForm.invalid">
Create course</button>
</ng-container>
<ng-container *ngIf="!createAnotherCheckbox.checked">
<button mat-raised-button type="button" (click)="Submit()" [disabled]="courseForm.invalid"
mat-dialog-close>Create course</button>
</ng-container>
uj5u.com熱心網友回復:
好的,謝謝,你是對的。我通過使用兩個 ng-container 解決了我的問題:
<ng-container *ngIf="createAnotherCheckbox.checked">
<button mat-raised-button type="reset" (click)="Submit()" [disabled]="courseForm.invalid">
Create course</button>
</ng-container>
<ng-container *ngIf="!createAnotherCheckbox.checked">
<button mat-raised-button type="button" (click)="Submit()" [disabled]="courseForm.invalid"
mat-dialog-close>Create course</button>
</ng-container>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/444562.html
