I have a single Angular2 component that I need to utilize across multiple modules. To achieve this, I created a SharedModule as shown below:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {GenericComponent} from './generic/generic.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ GenericComponent ],
exports: [ GenericComponent ]
})
export class SharedModule { }
Subsequently, I included the SharedModule in various modules like so:
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {SharedModule} from './shared.module';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule, SharedModule ],
declarations: [ AppComponent ],
exports: [ AppComponent ],
bootstrap: [AppComponent]
})
export class AppModule { }
I also integrated the SharedModule into generic.module.ts similarly:
generic.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {SharedModule} from './shared.module';
@NgModule({
imports: [ BrowserModule, SharedModule ],
declarations: [ //.. here I have added all the components that generic uses ]
})
export class GenericModule { }
However, upon attempting to use the generic component within other components of generic.module.ts, I encountered the following error:
Unexpected value 'undefined' imported by the module 'GenericModule'