0

GameService, UniqueIdService, GridService are my services used in a module.

Problem : core.js:5847 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(App4pcModule)

I have been trough these:

  1. ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule) uncaught-in-promise-error-staticinjectorerrorappmodule ==> does not apply to my case.

  2. https://stackoverflow.com/a/53775775/11584774 ==> tried this, does not help.

  3. https://github.com/angular/angular/issues/20339 ==> pretty much not related to me

@Injectable()
export class GameService {
    public currentScore: Observable<number>;
    public highScore: Observable<number>;
    public tiles: Observable<ITile[] >;
    public gameOver: Observable<boolean>;
    public won: Observable<boolean>;

    constructor(private gridService: GridService, private store:
        Store<any>) {
    const store$ = store.select<IGame>("game");
    this.tiles = store$.pipe(map(({ tiles }: IGame) =>
        tiles));
    this.currentScore = store$.pipe(
        map(({ currentScore }: IGame) => currentScore)
    );
    this.highScore = store$.pipe(map(({ highScore }: IGame) =>
        highScore));
    this.gameOver = store$.pipe(map(({ gameOver }: IGame) =>
        gameOver));
    this.won = store$.pipe(map(({ won }: IGame) => won));
}
...
}

@NgModule({
    declarations: [TileComponent, MessageComponent,
        GridComponent],
    imports: [BrowserModule, StoreModule.forRoot({ game:
        gameReducer })],
    providers: [GridService, UniqueIdService, GameService]
})
export class AppModule {}
Problem : core.js:5847 ERROR Error: Uncaught (in promise):
NullInjectorError: StaticInjectorError(App4pcModule)

    `stack trace on chromium`:
core.js:5847 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(App4pcModule)[Game48Component -> GameService]:
StaticInjectorError(Platform: core)[Game48Component -> GameService]:
NullInjectorError: No provider for GameService!
    NullInjectorError: StaticInjectorError(App4pcModule)[Game48Component -> GameService]:
StaticInjectorError(Platform: core)[Game48Component -> GameService]:
NullInjectorError: No provider for GameService!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1225)
at resolveToken (core.js:1463)
at tryResolveToken (core.js:1407)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1311)
at resolveToken (core.js:1463)
at tryResolveToken (core.js:1407)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1311)
at resolveNgModuleDep (core.js:18446)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:19135)
at resolveDep (core.js:19506)
at resolvePromise (zone.js:852)
at resolvePromise (zone.js:809)
at zone.js:913
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:24328)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
at
ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502)
at invokeTask (zone.js:1693)

1 Answer 1

2

This happens when no modules is providing your service. either provide your services in the app.module or change your services to include this

@Injectable({
  providedIn: 'root'
})

export class YourService { .....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.