角度2形式 – 在子组件级别分配ngControl
发布时间:2020-12-17 07:34:46 所属栏目:安全 来源:网络整理
导读:在角度2表格中, 尝试通过ngSubmit获取数据. 我可以在我的表单组件中分配ngModel和ngControl属性,但是在MyInput子组件中,我不能在没有“不提供错误”的情况下分配ngControl. Plunker这里 http://plnkr.co/edit/LauhEz6vMaEmIg0hceoj?p=preview directives: [C
在角度2表格中,
尝试通过ngSubmit获取数据. 我可以在我的表单组件中分配ngModel和ngControl属性,但是在MyInput子组件中,我不能在没有“不提供错误”的情况下分配ngControl. Plunker这里 http://plnkr.co/edit/LauhEz6vMaEmIg0hceoj?p=preview directives: [CORE_DIRECTIVES,FORM_DIRECTIVES,MyInput],template: ` <div> <form #hf="ngForm" (ngSubmit)="onSubmit(hf.value)"> <div> In Form: <input type='text' [ngControl]="inform" [(ngModel)]="theValue" [required]="req" #spy > <br>Classes: {{spy.className}} <br> <br>In Component: <my-input [props]='prop'></my-input> <br>In Component: <my-input [props]='prop2'></my-input> </div> <button type="submit" [hidden] = "!editing">Save</button> <button type="button" (click)="cancelClick()" [hidden] = "!editing">Cancel</button> <button type="button" (click)="setEdit(true)" [hidden] = "editing">Edit</button> </form> Form Values {{data}} </div> ` 子组件模板: @Component({ selector: 'my-input',directives: [FORM_DIRECTIVES],template: ` <input type='text' [(ngModel)]="props.Value" 如果我添加这个错误 [ngControl]="props.id" 有什么需要从表单传递给子组件吗?
在ngControl绑定/执行时,prop不可用的问题…如果您在组件中提供了一个默认控件,然后从ngOnChange中的道具中执行该操作,该操作将在道具真正可用的时间.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |