首页 > 解决方案 > 使用库中声明的角度组件时出错

问题描述

我创建了一个带有一些常见组件和一个 2 角度应用程序的角度工作区,但是当我尝试在角度应用程序中使用它时,它给了我这个错误:

“错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。”

这是 app.module.ts:

import { FormControlComponent } from 'my-library';
...
imports: [
    BrowserModule,
    AppRoutingModule,
    FormControlComponent,
  ],

我的图书馆有这个代码:

我的库.module.ts

declarations: [
  ...
  FormControlComponent,
  ...
],

exports: [
  ...
  FormControlComponent,
  ...
],

我的 public-api.ts 有这个代码:

export * from './lib/form-control/form-control.component';

我构建了库并添加到 package.json:

“我的图书馆”:“文件:dist/我的图书馆”,

标签: angularangular-library

解决方案


推荐阅读