In my Angular 2 application, I have created an ExchangeService
class that is decorated with @Injectable
. This service is included in the main module of my application:
@NgModule({
imports: [
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule,
ExchangeService,
RouterModule.forRoot(routes)
],
providers: [
{
provide: LocationStrategy,
useClass: HashLocationStrategy
},
ExchangeService
]
...})
However, I encounter an Exception:
(index):16 Error: (SystemJS) Unexpected value 'ExchangeService' imported by the module 'Application5'
Error: Unexpected value 'ExchangeService' imported by the module 'Application5'
Error: (SystemJS) Unexpected value imported by the module Error: Unexpected value imported by the module
Error: Unexpected value imported by the module at eval (http://127.0.0.1:8080/node_modules/@angular/compiler/bundles/compiler.umd.js:13982:37) at Array.forEach (native) at CompileMetadataResolver.getNgModuleMetadata
Error: Unexpected value imported by the module at eval at Array.forEach (native) at CompileMetadataResolver.getNgModuleMetadata
The exception disappears when I remove ExchangeService
from the imports
section and keep it only in the providers
section. While I don't explicitly require ExchangeService
to be in the imports
section, I want it to be globally available for injection in other services and components.
My question is - why am I not able to include ExchangeService
in the imports
section? The imports
section includes other TypeScript classes such as HttpModule
, so why is ExchangeService
restricted from being included there as well?