在Angular 2中使用模板驱动的表单,我想在表单中使用子组件,以便更容易地对表单元素进行单元测试 . 话虽如此,我希望能够使用模板引用变量(即) button [disabled]="!myForm.form.valid"
禁用提交按钮 . 我知道应该从父表单传递给子组件,但是我无法确定它是什么,或者应该使用的语法 .
使用Stackblitz示例,如果输入验证器(在此示例中特别是 minlength
)位于表单的子组件内,我将如何禁用提交按钮?
Stackblitz示例https://stackblitz.com/edit/angular-zzeton
我查看了以下链接,但他们有更多的todo与真正的输入控制自定义与访问模板引用变量:
How to add validation in template driven form from component in angular 6 https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html#demos
1 回答
声明ControlContainer
分叉示例:https://stackblitz.com/edit/angular-vmqm8h参考:https://medium.com/@a.yurich.zuev/angular-nested-template-driven-form-4a3de2042475