balajivaishnav
balajivaishnav

Reputation: 2893

Need to pass data to child component using Form group in angular 2?

Am trying to pass data using @Input from parent to child component, where parent and child both are using form group and the control are accessed by the child component by @Input, whereas if I need to pass some data to the child component using @input decorator am getting Error

Parent Component.html

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

Child Component.ts

 @Input('generalrulegroup')

@Input()mydata:any;

Console Error

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)

Upvotes: 1

Views: 427

Answers (1)

SrAxi
SrAxi

Reputation: 20005

Try this:

@Input('generalrulegroup') generalrulegroup: any;

You need to declare it in the current component.

Upvotes: 1

Related Questions