[英]Is it possible to pass form valid reference to ng-template in angular
I'm using Angular 8 and I have the below code structure.我正在使用 Angular 8 并且我有以下代码结构。
<div class="addForm" *ngIf="activeForm == 1">
<form [formGroup]="addForm1">
<div>
---
---
<!-- footer area -->
<ng-container *ngTemplateOutlet="submitCancelAndReset;context:{isValid: this.addForm1.valid}"></ng-container>
</div>
</form>
</div>
<div class="addForm" *ngIf="activeForm == 2">
<form [formGroup]="addForm2">
<div>
---
---
<!-- footer area -->
<ng-container *ngTemplateOutlet="submitCancelAndReset;context:{isValid: this.addForm2.valid}"></ng-container>
</div>
</form>
</div>
<div class="addForm" *ngIf="activeForm == 3">
<form [formGroup]="addForm3">
<div>
---
---
<!-- footer area -->
<ng-container *ngTemplateOutlet="submitCancelAndReset;context:{isValid: this.addForm3.valid}"></ng-container>
</div>
</form>
</div>
<ng-template #submitCancelAndReset let-isValid="isValid">
---
---
<button type="submit" [disabled]="!isValid">SAVE</button>
---
---
</ng-template>
Here, the footer area is same for all three forms and so I created a common ng-template which includes a submit button with dynamic disabled property.在这里,所有三个 forms 的页脚区域都是相同的,所以我创建了一个通用的 ng 模板,其中包括一个带有动态禁用属性的提交按钮。 Now I need to pass each form's valid state as input parameter to the ng-template, which will bind to the disabled property.. Is that possible?现在我需要将每个表单的有效 state 作为输入参数传递给 ng-template,它将绑定到 disabled 属性。这可能吗?
After hours of debugging I found out that there was an extra validation method that is based on an optional API call for form2 and form3, and unfortunately I used OR condition instead of AND..经过数小时的调试,我发现有一个额外的验证方法,它基于对 form2 和 form3 的可选 API 调用,不幸的是我使用 OR 条件而不是 AND..
FYI - This issue is resolved and it is possible to pass different form's reference to a common ng-template using above code.仅供参考 -此问题已解决,可以使用上述代码将不同表单的引用传递给通用 ng-template。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.