Maybe this is sort of two questions in one. I know you have to explicitly declare directives to be used inside a Component for Angular 2. Does this propagate to children Components of the Component, and if not, can it be made to? Second, do variables declared on the Component propagate to children, or do they have to be explicitly passed to the Component?
As of beta.14 you have to explicitly list all used directives in @Component
's directives
array. For the second part of the question, variables declared on component (eg: this.name
) are not propagated to child components. To achieve that you have to pass them explicitly in components template using attributes like <child [item]="parentItem"></child>
and child component must contain @Input item
property.
EDIT:
To incorporate clarification from comment... It is possible to register directives globally but only in bootstrap
function. Directives declared on parent will NOT be inherited by child component.
bootstrap(App, [
PLATFORM_DIRECTIVES,
provide(PLATFORM_DIRECTIVES, {useValue: [SomeDirective, SomeComponent], multi:true})
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With