Error when calling NotificationsService from Service class.
I want to call the NotificationsService from a centralized location (Angular Service class), but when the NotificationsService is injected in the constructor class, I get the following error:
Error: Can't resolve all parameters for NotificationWrapService: (?).
at SyntaxError.ZoneAwareError (http://localhost:4200/polyfills.bundle.js:3401:33)
at SyntaxError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:85542:16)
at new SyntaxError (http://localhost:4200/vendor.bundle.js:6513:16)
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:4200/vendor.bundle.js:21339:31)
at CompileMetadataResolver._getTypeMetadata (http://localhost:4200/vendor.bundle.js:21214:26)
at CompileMetadataResolver._getInjectableMetadata (http://localhost:4200/vendor.bundle.js:21202:21)
at CompileMetadataResolver.getProviderMetadata (http://localhost:4200/vendor.bundle.js:21444:40)
at http://localhost:4200/vendor.bundle.js:21402:49
at Array.forEach (native)
at CompileMetadataResolver._getProvidersMetadata (http://localhost:4200/vendor.bundle.js:21369:19)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:4200/vendor.bundle.js:21053:50)
at JitCompiler._loadModules (http://localhost:4200/vendor.bundle.js:58970:64)
at JitCompiler._compileModuleAndComponents (http://localhost:4200/vendor.bundle.js:58930:52)
at JitCompiler.compileModuleAsync (http://localhost:4200/vendor.bundle.js:58896:21)
at PlatformRef_._bootstrapModuleWithZone (http://localhost:4200/vendor.bundle.js:44146:25)
I use angular-cli (1.0.0) that uses webpack:
app.module.ts
...
@NgModule({
declarations: [...],
imports: [
BrowserModule,
FormsModule,
HttpModule,
SimpleNotificationsModule.forRoot(), // <--- HERE
AppRoutingModule,
MaterialModule,
AngularFireModule.initializeApp(firebaseConfig),
FlexLayoutModule.forRoot()
],
providers: [...],
bootstrap: [AppComponent]
})
My service NotificationWrapService.ts
import { NotificationsService } from 'angular2-notifications';
export class NotificationWrapService {
constructor(private toaster: NotificationsService) { } // When the service injected I get the error
success = (title: string, message: string): void => {
this.toaster.success(title, message);
}
}
Am I importing it in a wrong way inside the service?
If I call the NotificationsService directly inside a component, it works fine.
Which version do you use?
We don't really have such a wrapper class, but using 2.0.0 I am unable to notify from our AuthRestService, which has NotificationsService injected and calls:
this.notificationsService.error('Erreur', message);
We have no problem with injection, there is no error neither compiling nor when the statement runs, but no message displays, while it works when the same statement is in components.