小编Zen*_*en 的帖子

自定义库组件不是已知元素,但应用程序编译并运行

问题

我的 html 文件警告我的自定义组件/管道“不是已知元素”。然而,构建和运行应用程序按预期工作,并且自定义组件/管道可以正常工作。组件工作但显示为错误的二分法令人讨厌并且可能难以使用。我知道这是一件小事,但我真的不想在没有错误的情况下在我的 html 文件中看到错误。

概括

我有两个不同的角度项目;我在我的 angular 应用程序中使用的 angular 库。该库导出应用程序使用的多个自定义组件、管道和服务。我没有通过 npm 发布这个库,而是使用 npm-link 为应用程序提供对该库的访问权限。这似乎可以作为我的应用程序组件中定义的任何服务/组件工作并且不会抱怨。尽管我将库中的任何内容放入模板文件的那一刻,该选择器带有下划线并出现警告。

文件

/*Library Module*/
@NgModule({
  declarations: [
    ThemeToggleComponent,
    // Other custom components/pipes
  ],
  exports: [
    ThemeToggleComponent,
    // Other components needed in templates files
  ]
})
export class MyCommonModule {}
  
Run Code Online (Sandbox Code Playgroud)
/*
 * Public API Surface of my-common library
 */

export * from './lib/my-common.module';
/*
 * Many other components, services, pipes, etc etc
 */
export * from './lib/theme-toggle/theme-toggle.component';

Run Code Online (Sandbox Code Playgroud)
/* Consuming Application module */
import { …
Run Code Online (Sandbox Code Playgroud)

html npm typescript visual-studio-code angular

25
推荐指数
3
解决办法
6617
查看次数

标签 统计

angular ×1

html ×1

npm ×1

typescript ×1

visual-studio-code ×1