I'm creating Web apps using Angular2 with TypeScript. When I created some CustomElements (it's mean Components and Directives, Validators), I found that I wrote directives: [...]
code to every Components in order to import CustomElements like the below code.
// my_comopnent_1.comopnent.ts
@Component({
selector: 'my-component-1',
directives: [
ROUTER_DIRECTIVES,
MyDirective1,
MyDirective2,
MyValidator1,
MyValidator2,
...
],
})
// my_comopnent_2.comopnent.ts
@Component({
selector: 'my-component-2',
directives: [
ROUTER_DIRECTIVES,
MyDirective1,
MyDirective2,
MyValidator1,
MyValidator2,
...
],
})
// my_comopnent_3.comopnent.ts
@Component({
selector: 'my-component-3',
directives: [
ROUTER_DIRECTIVES,
MyDirective1,
MyDirective2,
MyValidator1,
MyValidator2,
...
],
})
Does the way exist how some CustomComopnents can be imported without repeatedly writing directives: [...]
, like event bubbling or prototype chain?
My ideal is that when I write the code to parent Components, its child Components includes them parent's imported CustomElements.
// parent.component.ts
@Component({
selector: 'parent',
directives: [MyDirective1, ...],
})
// child.component.ts
@Component({
selector: 'child',
template: `
// It's possible to use MyDirective because of importing by ParentComponent.
<div my-directive></div>
`,
})