0

I have simple module SomeOtherModule and i want that it's CounterComponent is available as path in AppModule.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CounterService } from '../services/counter.service';
import { CounterComponent } from '../counter/counter.component';
@NgModule({  
  imports: [ CommonModule],
  providers: [CounterService],
  declarations: [  CounterComponent ],
  exports: [CounterComponent] 
})
export class SomeOtherModule { }

and AppModule:

import { SomeOtherModule } from './some-other/some-other.module';
@NgModule({
    declarations: [
       AppComponent,  
       HomeComponent,     
       CounterComponent, 
    ],
    imports: [SomeOtherModule,
         RouterModule.forRoot([
          { path: '', component: HomeComponent, pathMatch: 'full' },
          { path: 'counter', component: CounterComponent }, 
     ]
)]

TS error on CounterComponent not found

1
  • You could specify your component path in a SomeOtherRoutingModule an then redirect 'counter' to the SomeOtherModule from the AppModule. Commented May 22, 2018 at 8:05

1 Answer 1

1

In your AppModule, remove CounterComponent from declarations module property. He is already declared onSomeOtherModule.

EDIT: I don't know if you cut it for the question, but if not, you forgot to import CounterComponent in your AppModule files.

Sign up to request clarification or add additional context in comments.

7 Comments

Neither works. I cut BrowserModule for simplicity as AppModule has 20+ dependencies
@ВладимирЛапенков Okey, my bad. In your AppModule, did you import CounterComponent ?
No. I thought it belongs to another module so i don't need to explicit import { CounterComponent } from './counter/counter.component';
@ВладимирЛапенков import from ES and import from NgModule are totally differents. If you write component: CounterComponent explicitly on AppModule, then, you need to import CounterComponent. Just try it :) if I wrong, I will learned something
You mean i should import CounterComponent in @NgModule of AppModule?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.