javascript - Using component encapsulated in a module from other module in angular 4 -


i developing angular 4 app , have 2 modules, first module encapsulate features need use in others modules. example have first module called srmodule have imported srcrcomponent component:

import { ngmodule } '@angular/core'; import { commonmodule } '@angular/common';   // module imports import { srcrcomponent} './sr-cr';  @ngmodule({   imports: [     commonmodule   ],   exports: [     srcrcomponent   ],   declarations: [     srcrcomponent   ] }) export class srmodule {} 

i want use srcrcomponent in other component of module, can figure out how use.

in second module called reportsmodule, have imported srmodule on it

import { ngmodule } '@angular/core'; import { commonmodule } '@angular/common'; import { cpcomponent } './cp/cp.component'; import { srmodule } "../sr-module/sr.module";  @ngmodule({   imports: [     commonmodule,     srmodule   ],   declarations: [     cpcomponent   ] }) export class reportsmodule { } 

my question here is, how use srcrcomponent component declared inside cpcomponent on reportsmodule?

this cpcomponent ts file:

import { component, oninit } '@angular/core'; @component({   selector: 'app-chart-period',   templateurl: './chart-period.component.html',   styleurls: ['./chart-period.component.css'] }) export class cpcomponent implements oninit {    constructor() { }    ngoninit() {   } } 

in html of cpcomponent have sr-gg component not work,

<h2> bar chart</h2> <sr-gg></sr-gg> 

oviously 'sr-g' not known element in reportsmodule, in fac, error console showed me, don't know need declare or should inherit when import srcrcomponen.

reportsmodule imports srmodule , thereby srmodule pointed out in exports : [] in case srcrcomponent. assume cpcomponent should part of reportsmodule, i.e cpcomponent should mentioned in declarations : [] reportsmodule. mention sr-gg component if should declared in srmodule exports should exports : [srcrcomponent, srggcomponent]

 @ngmodule({       imports: [          commonmodule       ],       exports: [          srcrcomponent, srggcomponent       ],       declarations: [         srcrcomponent, srggcomponent       ] }) export class srmodule {} 

and

    @ngmodule({       imports: [         commonmodule,         srmodule       ],       declarations: [         reportscomponent,         chartperiodcomponent,         chartsegmentationcomponent,         cpcomponent       ]  })  export class reportsmodule { } 

then should work


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -