импорт класса ES5 в машинописный текст с помощью angular8 выдает NullInjectorError: StaticInjectorError - PullRequest
0 голосов
/ 17 июня 2019

GameService, UniqueIdService, GridService - мои услуги, используемые в модуле.

Проблема: core.js: 5847 ОШИБКА Ошибка: Uncaught (в обещании): NullInjectorError: StaticInjectorError (App4pcModule)

Я прошел через это:

  1. ОШИБКА Ошибка: Uncaught (в обещании): Ошибка: StaticInjectorError (AppModule) uncaught-in-обещание-error-staticinjectorerrorappmodule ==> делает не относится к моему делу.

  2. https://stackoverflow.com/a/53775775/11584774 ==> пробовал это, не помогает.

  3. https://github.com/angular/angular/issues/20339 ==> в значительной степени не связаны со мной

@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 Ответ

1 голос
/ 17 июня 2019

это происходит, когда ни один модуль не предоставляет ваш сервис.либо предоставьте свои услуги в app.module, либо измените их на

@Injectable({
  providedIn: 'root'
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...