angular - Angular - 子组件的表单无效
问题描述
我正在建立一个表格。有些字段是必需的。
<form #f = "ngForm">
[...]
<mat-form-field fxFlex = "10">
<mat-label translate> location.code </mat-label>
<input matInput type="text" required placeholder="" [(ngModel)]="location.code" name="code">
</mat-form-field>
[...]
<inner-form-component [model]="location.innermodel"></inner-form-component>
</form>
<button mat-raised-button color="primary" (click)="save()" [disabled]="f.invalid">
<mat-icon>save</mat-icon>
{{ 'generic.submit' | translate }}
</button>
如果某些必填字段未填写,保存按钮将自动禁用。不幸的是,它不适用于添加其他字段的子组件(内部表单组件)继承的字段。
有没有办法让Angular也用它们禁用按钮?
解决方案
看看这篇文章:https ://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475
您可能在ControlContainer
内部组件中缺少 viewProvider
推荐阅读
- c - 有没有办法将 stderr 重定向到在 bash、csh 和 dash 中工作的文件?
- selenium - 如何使用 Kantu Selenium IDE 获取整个元素?
- cors - quarkus:被 CORS 策略阻止
- angular - Cypress.io 测试下拉列表
- apache-kafka - 在 Ubuntu linux 中启动 Kafka 服务器时出错
- javascript - 你将如何重构这个 Javascript 对象循环?
- javascript - 在 vue.js 中创建一个包含数据的 obj 名称
- javascript - 为什么这种将 html 表单信息下载为字符串/.txt 文件的方法会从文件中删除所有换行符?
- python-3.x - 结束 LTSpice 模拟的指令
- tableau-api - 如何修复在订单中检查日期的计算字段?