javascript - Declaration of directive or component in defferent modules, angular 4 -
is possable declare 1 directive/component many modules? can export one:
import { directive, elementref } '@angular/core'; @directive({ selector: '[appbigtext]' }) export class bigtextdirective { constructor(el: elementref) { el.nativeelement.style.fontsize = '100px' } } module one: import { bigtextdirective } '../common/directives/dir225'; @ngmodule({ imports: [httpmodule........... providers :[homeservice], declarations: [ homecomponent, detailcomponent, bigtextdirective ] component: import { bigtextdirective } '../common/directives/dir225'; @component({ selector: 'my-app', template: ` <router-outlet></router-outlet> <div appbigtext>this text huge.</div>. ` }) module 2 same inculding, have error
in case need using same component/directive in multiple modules, means it's common. why don't follow error suggestion , extract bigtextdirective
separate module , export it?
ngmodule({ // ... providers: [ bigtexttexture ] exports: [ bigtexttexture ] }) export class commonmodule {}
so can re-use in high-level modules importing it:
@ngmodule({ imports: [ commonmodule ], declaration: [ ineedbigtexttexturecomponent ] }) export class highlevelmodule {}
let angular helps code organization!
Comments
Post a Comment