Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directive/scope inheritance

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?

like image 513
djvs Avatar asked Oct 15 '15 13:10

djvs


1 Answers

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})
]);
like image 157
tomastrajan Avatar answered Sep 28 '22 14:09

tomastrajan