加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 非法状态:无法加载指令NgClass的摘要

发布时间:2020-12-17 17:10:58 所属栏目:安全 来源:网络整理
导读:在我的模块上运行ngc时,它使用angular 4.4.3(和编译器4.4.3)工作正常.现在我升级到5.0.0(角度和编译器),我有以下错误: Error: Illegal state: Could not load the summary for directive NgClass in […]/node_modules/@angular/common/common.d.ts. 我的ts
在我的模块上运行ngc时,它使用angular 4.4.3(和编译器4.4.3)工作正常.现在我升级到5.0.0(角度和编译器),我有以下错误:

Error: Illegal state: Could not load the summary for directive NgClass in […]/node_modules/@angular/common/common.d.ts.

我的tsconfig.json文件如下所示:

{
  "compilerOptions": {
    "baseUrl": ".","declaration": true,"stripInternal": true,"experimentalDecorators": true,"emitDecoratorMetadata": true,"module": "es2015","moduleResolution": "node","outDir": "[...]/","paths": {...},"rootDir": "[...]/plugins/","target": "es5","skipLibCheck": true,"lib": [
      "es2015","dom"
    ],"sourceMap": true,"inlineSources": true,"noImplicitAny": true
  },"files": [
    "[...]/plugins/users/index.ts"
  ]
}

我不知道从我试图编译的文件中导致问题的原因是什么.我在这里和那里看到过类似的错误,但是直接与公共模块无关.发布样本以重现错误很困难,因为它不会发生在其他模块上

编辑1:

我的设置如下:一个模块MyModuleA成功构建,MyModuleB使用不构建的MyModuleA.

@NgModule({
  imports: [
    CommonModule,IonicModule,TranslateModule.forChild()
  ]
})
export class MyModuleA {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleA,providers: [
        ModuleAService
      ]
    };
  }
}

@NgModule({
  imports: [
    HttpClientModule,MyModuleA
  ]
})
export class MyModuleB {
  /**
   * Instantiate module (for main module only).
   */
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleB,providers: [
        ModuleBService
      ]
    }
  }
}

如果我在MyModuleB中包含CommonModule,我还有另一个错误:

Error: Illegal state: Could not load the summary for directive ActionSheetCmp in [...]/node_modules/ionic-angular/components/action-sheet/action-sheet-component.d.ts

现在我可以在MyModuleB中包含IonicModule以获得下一个非法状态错误(这次链接到translate模块),但我在MyModuleB中根本没有使用这些模块,那么为什么我需要将它们全部导入呢?

解决方法

所以我不确定这背后的原因是什么,这很烦人,但似乎每个导入的模块都需要由子模块导入或从父模块导出.所以在我的例子中,解决方案是:

@NgModule({
  imports: [
    CommonModule,TranslateModule.forChild()
  ],exports: [
    CommonModule,TranslateModule
  ]
})
export class MyModuleA {
  static forRoot(): ModuleWithProviders {
    return {
      ngModule: MyModuleA,providers: [
        ModuleBService
      ]
    }
  }
}

如果有人知道为什么,请随时赐教:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读