使用此资源,我想在多个嵌套级别上实现 formControlName。
Angular 2 - 组件内的 formControlName
假设实际的 formGroup 比子 formControlName 组件高 3 个组件级别,
如果父组件紧挨着子组件,则 ControlValueAccessor 起作用。然而,以上(祖父)形式的多个级别不起作用。
是否有服务或多个输入/输出的替代方案?或者这些是唯一的方法?
A--> Component with formGroup
B---> Component container
C---> Component container
D ---> Component with FormControlName (should pass to Component A)
Run Code Online (Sandbox Code Playgroud)
组件A会从类似的不同子组件中收集多个表单控件名称,
输入文本.ts
export class InputTextComponent implements AfterViewInit, ControlValueAccessor {
@Input() disabled: boolean;
@Output() saveValue = new EventEmitter();
value: string;
onChange: () => void;
onTouched: () => void;
writeValue(value: any) {
this.value = value ? value : "";
}
registerOnChange(fn: any) {this.onChange = …Run Code Online (Sandbox Code Playgroud) 这是我的模型.ts
export class Feature2 {
requestRouteTemplate: string;
requestMethod: string;
numberCount: number;
requestDate: date;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
Run Code Online (Sandbox Code Playgroud)
这是组件.ts
this.datas2 = [
{
'requestRouteTemplate': 'api/Tasks',
'requestMethod': 'POST',
'numberCount': 6,
'requestDate': '07/01/2017',
},
{
'requestRouteTemplate': 'api/Tasks',
'requestMethod': 'POST',
'numberCount': 3,
'requestDate': '07/02/2017',
},
Run Code Online (Sandbox Code Playgroud)
我想使用 moment 库将请求日期变量从字符串转换为日期。