I\'ve got a problem loading a class into an Angular component. I\'ve been trying to solve it for a long time; I\'ve even tried joining it all in a single file. What I have i
You should be injecting NameService
inside providers
array of your AppModule
's NgModule
metadata.
@NgModule({
imports: [BrowserModule, ...],
declarations: [...],
bootstrap: [AppComponent],
//inject providers below if you want single instance to be share amongst app
providers: [MyService]
})
export class AppModule {
}
If you want to create an Dependency for particular component level without bothering about state of your application, then you can inject that dependency on component providers
metadata option like accepted @Klass answer shown.