angular2-notifications icon indicating copy to clipboard operation
angular2-notifications copied to clipboard

No provider for NotificationsService even with .forRoot()

Open iowaz opened this issue 8 years ago • 4 comments

Hi.

I'm getting a error in one of my projects only with AOT build.

In my app.module.ts I have imported it just like the documentation says:

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {NgModule, LOCALE_ID} from '@angular/core';

import {AppComponent} from './app.component';
import {SharedModule} from './shared/modules/shared.module';
import {RoutesModule} from './shared/modules/routes.module';

import {SimpleNotificationsModule} from 'angular2-notifications';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        **SimpleNotificationsModule.forRoot()**,
        SharedModule,
        RoutesModule,
    ],
    exports: [],
    providers: [{provide: LOCALE_ID, useValue: 'pt-BR'}],
    bootstrap: [AppComponent]
})
export class AppModule {
}

The build doesn't fail, but when I get into my page I gotta this error in console: ERROR Error: Uncaught (in promise): Error: No provider for NotificationsService! Error: No provider for NotificationsService! at injectionError (core.es5.js:1169) at noProviderError (core.es5.js:1207) at ReflectiveInjector_._throwOrNull (core.es5.js:2649) at ReflectiveInjector_._getByKeyDefault (core.es5.js:2688) at ReflectiveInjector_._getByKey (core.es5.js:2620) at ReflectiveInjector_.get (core.es5.js:2489) at resolveNgModuleDep (core.es5.js:9492) at _createClass (core.es5.js:9533) at _createProviderInstance$1 (core.es5.js:9503) at resolveNgModuleDep (core.es5.js:9488) at injectionError (core.es5.js:1169) at noProviderError (core.es5.js:1207) at ReflectiveInjector_._throwOrNull (core.es5.js:2649) at ReflectiveInjector_._getByKeyDefault (core.es5.js:2688) at ReflectiveInjector_._getByKey (core.es5.js:2620) at ReflectiveInjector_.get (core.es5.js:2489) at resolveNgModuleDep (core.es5.js:9492) at _createClass (core.es5.js:9533) at _createProviderInstance$1 (core.es5.js:9503) at resolveNgModuleDep (core.es5.js:9488) at resolvePromise (zone.js:783) at resolvePromise (zone.js:754) at eval (zone.js:831) at ZoneDelegate.invokeTask (zone.js:424) at Object.onInvokeTask (core.es5.js:3881) at ZoneDelegate.invokeTask (zone.js:423) at Zone.runTask (zone.js:191) at drainMicroTaskQueue (zone.js:595) at <anonymous>

This is my package.json:

"dependencies": {
    "@angular/animations": "4.4.6",
    "@angular/cdk": "2.0.0-beta.12",
    "@angular/common": "4.4.6",
    "@angular/compiler": "4.4.6",
    "@angular/core": "4.4.6",
    "@angular/forms": "4.4.6",
    "@angular/http": "4.4.6",
    "@angular/material": "2.0.0-beta.12",
    "@angular/platform-browser": "4.4.6",
    "@angular/platform-browser-dynamic": "4.4.6",
    "@angular/router": "4.4.6",
    "@covalent/core": "1.0.0-beta.8-1",
    "@covalent/text-editor": "^1.0.0-beta.1",
    "angular2-image-upload": "^1.0.0-rc.0",
    "angular2-jwt": "0.2.3",
    "angular2-notifications": "^0.7.8",
    "core-js": "2.4.1",
    "hammerjs": "2.0.8",
    "lodash": "^4.17.4",
    "moment": "^2.19.1",
    "mydaterangepicker": "^4.1.11",
    "rxjs": "5.4.2",
    "zone.js": "0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.6.0",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.93",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.3.3"
  }

Can anyone help me to point at my error?

PS: with JIT it works perfectly. PS 2: I even tried to import it on my Shared and Routes modules, it doesn't appear to help in anything.

iowaz avatar Dec 27 '17 12:12 iowaz

Same error on my side

balazsnemeth avatar Apr 04 '18 10:04 balazsnemeth

This is a working example. Can you please fork it and reproduce your error?

https://stackblitz.com/edit/angular2-notifications-example

flauc avatar Apr 04 '18 11:04 flauc

@flauc , thanks for your quick response!

I have almost the same dependency as @iowaz has above, like angular 4.4.6, so we cannot work with the latest version of angular2-notifications, but only the version "0.7.8" I think.

I will try to create a plunker with our setup

balazsnemeth avatar Apr 04 '18 11:04 balazsnemeth

Did you manage toi find a solution to this issue with AOT?

abielikesu avatar Aug 23 '18 11:08 abielikesu