I have written a SharedModule to share common pipes, directives and components across multiple modules. Now I have to move a component to the SharedModule to use it in multiple modules which also gets a service injected.
This is the error I am getting:
EXCEPTION: Uncaught (in promise): Error: Can't resolve all parameters for ChooseArticleModalComponent: (Http, ?).
The component was working just fine with the service injected outside of the SharedModule in an other module.
The service I want to inject is defined in the AppModule (Root Module), so from what I understand it should be global available in my application.
article.service.ts
import { Injectable } from '@angular/core';
import { Article, ProductCategorie } from '../_models/index';
@Injectable()
export class ArticleService {
getAllProduktCategoriesForArticles(articles: Article[]): ProductCategorie[] {
…
return productCategories;
}
}
shared.module.ts
import { ChooseArticleModalComponent } from '../inquiry/inquiry-create-choose-articles/choose-article-modal/choose-article-modal.component.ts';
…
@NgModule({
imports: [
…
],
declarations: [
…
ChooseArticleModalComponent,
],
exports: [
…
ChooseArticleModalComponent
],
})
export class SharedModule {
}
app.module.ts
import { NgModule, ApplicationRef, ViewContainerRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
…
import { ArticleService } from './_services/article.service';
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
ErrorComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(ROUTES, { useHash: true }),
],
providers: [
ArticleService,
…
]
})
export class AppModule {
…
}
choose-article-modal.component.ts
import { Component, ViewChild, OnInit, Input, Output, EventEmitter, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { ArticleService } from '../../../_services/index';
@Component({
selector: 'choose-article-modal',
templateUrl: './choose-article-modal.template.html',
})
export class ChooseArticleModalComponent {
…
constructor(private http: Http, private articleService: ArticleService) {
…
}
…
}
I injected the Http service only to test if angular services would work and they seem to be injected properly.
What needs to be modified to resolve this issue?
I am using angular2 final
All my modules except the SharedModule are imported like this:
export const ROUTES: Routes = [ {
path: 'app', loadChildren: () => System.import('./layout/layout.module')}
}];