Using a component from another module in Angular 4

I have a RoomComponent in the AppModule, its route is / rooms. I also have a lazy CompaniesModule module with CompaniesComponent component with route / companies.

I am trying to build a route, for example / companies / {company_id} / rooms /, when RoomComponent is reused from the AppModule.

I can’t do this, but longCommonComponent is not declared in CompanyModule, but it causes me an error because the component cannot be declared in several modules.

+4
source share
1 answer

Declare RoomsComponent in the Shared module, and then import this shared module into the modules that need it. The following is an example of one of my common modules:

import { NgModule }  from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

import { StarComponent } from './star.component';

@NgModule({
  imports: [ CommonModule],
  exports : [
    CommonModule,
    FormsModule,
    StarComponent
  ],
  declarations: [ StarComponent ],
})
export class SharedModule { }

, StarComponent . , , .

+17

Source: https://habr.com/ru/post/1680693/


All Articles