【问题标题】:Undescribed Angular NG0203 console message未描述的 Angular NG0203 控制台消息
【发布时间】:2022-07-19 15:33:44
【问题描述】:

当我将 MatProgressSpinnerModule 加载到 app.module.ts 中时,出现“stacktrace”为空的 NG0203 错误:

    tQ https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    re https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    fac https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    hydrate https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    get https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    _resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    _resolveInjectorDefTypes https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    PM https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    create https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    onInvoke https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    bootstrapModuleFactory https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    wA https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    invoke https://localhost:44378/client/polyfills.js:1
    run https://localhost:44378/client/polyfills.js:1
    F https://localhost:44378/client/polyfills.js:1
    invokeTask https://localhost:44378/client/polyfills.js:1
    runTask https://localhost:44378/client/polyfills.js:1
    L https://localhost:44378/client/polyfills.js:1
    promise callback*d https://localhost:44378/client/polyfills.js:1
    scheduleTask https://localhost:44378/client/polyfills.js:1
    scheduleTask https://localhost:44378/client/polyfills.js:1
    scheduleMicroTask https://localhost:44378/client/polyfills.js:1
    F https://localhost:44378/client/polyfills.js:1
    then https://localhost:44378/client/polyfills.js:1
    bootstrapModule https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    636 https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    n https://localhost:44378/client/runtime.js:1
    <anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1
    a https://localhost:44378/client/runtime.js:1
    <anonymous> https://localhost:44378/client/main.js?v=tGcUggioS9SQmuEwtHgBh_nWyK0V2FItGwwRHNtEq90:1

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from "@angular/common/http";
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';

import { AppComponent } from './app.component';
import { SongbookService } from './services/songbookService';
import router from './router';
import { InterceptorService } from './services/InterceptorService';
import { SpinnerService } from './services/spinnerService';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    BrowserAnimationsModule,
    MatProgressSpinnerModule,
    router
  ],
  providers: [
    SongbookService,
    { provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true },
    SpinnerService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

我不知道如何修复它,当我在 NgModule 导入中重新输入 MatProgressSpinnerModule 时 - 不会出现错误。 ngx-spinner 也有同样的问题。

如果它在 .NET 应用程序中的 SPA 很重要

【问题讨论】:

  • 你有没有发现你的问题?
  • 我遇到了这个错误,在我的情况下,我开发的一个库需要 ngRx 并且缺少一些配置。要了解原因是什么,诀窍是使用禁用优化添加 --optimization=false 来构建项目。如果你这样做,控制台上的错误应该很清楚。

标签: angular angular-cli


【解决方案1】:

我也经历了一个错误“NG0203 injection() must be called from an injection context”从一天到另一天没有真正改变什么。

我偶然发现了以下适用于我的解决方案: https://stackoverflow.com/a/61801741/18578004

建议调整tsconfig.json添加角度模块的路径如下:

{
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "paths": {
      //[...]
      "@angular/*": [ "./node_modules/@angular/*"]
    },
    //[...]
  }
}

希望对你有帮助...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多