需要使用角度2中的Form组将数据传递给子组件?

时间:2017-07-11 13:49:38

标签: angular

尝试使用@Input从父组件传递数据到子组件,其中父组件和子组件都使用表单组,子组件通过@Input访问控件,而如果我需要将一些数据传递给子组件使用@input装饰器的组件收到错误

Parent Component.html

 <rulebuilder [mydata]="ruledata" [generalrulegroup]="editRulesFrmGrp.controls.generalRule.controls[i]"></rulebuilder>

Child Component.ts

 @Input('generalrulegroup')

@Input()mydata:any;

控制台错误

Error: Template parse errors:
Can't bind to 'generalrulegroup' since it isn't a known property of 'modifygeneralrulebuilder'. ("<modifygeneralrulebuilder [mydata]="modifyRuleJson" [ERROR ->][generalrulegroup]="editRulesFrmGrp.controls.generalRule.controls[i]"></modifygeneralrulebuilde"): RuleEditComponent@108:128
    at SyntaxError.BaseError [as constructor] (http://localhost:4200/main.bundle.js:103798:27)
    at new SyntaxError (http://localhost:4200/main.bundle.js:9270:16)
    at TemplateParser.parse (http://localhost:4200/main.bundle.js:27281:19)
    at JitCompiler._compileTemplate (http://localhost:4200/main.bundle.js:65409:68)
    at http://localhost:4200/main.bundle.js:65292:62
    at Set.forEach (native)
    at JitCompiler._compileComponents (http://localhost:4200/main.bundle.js:65292:19)
    at createResult (http://localhost:4200/main.bundle.js:65175:19)
    at ZoneDelegate.invoke (http://localhost:4200/main.bundle.js:164194:26)
    at Zone.run (http://localhost:4200/main.bundle.js:164076:43)

1 个答案:

答案 0 :(得分:1)

试试这个:

@Input('generalrulegroup') generalrulegroup: any;

您需要在当前组件中声明它。