angular - Is there a way to use value from template in Angular2 dependency injection? -


i have angular2 component uses 2 sub components. template looks like

<component-a/> <component-b/> 

i inject component-a instance constructor of component-b. there way refer component-a in provider on root component?

that breaks whole purpose of making 2 components in first place. since making 1 dependant on other can't reuse them separately, might make them one.

create parent holds both components inside , info both need , set info each children component @inputs:

https://angular.io/docs/ts/latest/api/core/input-var.html

some raw example:

<component-a (modeselected)="selectedmode==$event"/> <component-b [mode]="selectedmode" /> 

or:

<component-a #modeselector/> <component-b [mode]="modeselector.selectedmode" /> 

() means output, [] means input.

in first example selectedmode property of parent controller holds both , b components inside. in second example selectedmode property of component a.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -