错误:“ clr-icon”不是已知元素:

时间:2019-01-24 22:49:08

标签: angular vmware-clarity

运行以下命令:

ng build --prod --base-href ./

我得到:

ERROR in : 'clr-icon' is not a known element:
1. If 'clr-icon' is an Angular component, then verify that it is part of this module.
2. If 'clr-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("spinner spinner-sm spinner-inverse" [style.display]="loading ? 'inline-block' : 'none'"></span>
    [ERROR ->]<clr-icon clrSignpostTrigger shape="check" size="20" class="is-info" [style.display]="!loading && req")

我使用的是Angular 7和Clarity 1.04。

从我的angular.json中提取:

        "styles": [
          "node_modules/@clr/icons/clr-icons.min.css",
          "node_modules/@clr/ui/clr-ui.min.css",
          "node_modules/prismjs/themes/prism-solarizedlight.css",
          "src/styles.css",
          "node_modules/lato-font/css/lato-font.min.css"
        ],
        "scripts": [
          "node_modules/core-js/client/shim.min.js",
          "node_modules/mutationobserver-shim/dist/mutationobserver.min.js",
          "node_modules/@webcomponents/custom-elements/custom-elements.min.js",
          "node_modules/web-animations-js/web-animations.min.js",
          "node_modules/prismjs/prism.js",
          "node_modules/prismjs/components/prism-typescript.min.js",
          "node_modules/@clr/icons/clr-icons.min.js"
        ]

关于如何调试的任何想法?

2 个答案:

答案 0 :(得分:1)

clr-icon是一个自定义元素,但是您可能知道这一点。

您是否可以尝试将其添加到polyfills.ts文件中(如果使用AngularCLI工具生成的文件,它应该与app/目录处于同一级别。

import '@webcomponents/custom-elements';
import '@clr/icons';

然后,将angular.json文件中的scripts数组删除为空,并查看它是否生成。如果确实开始,将其他脚本逐一放入列出的脚本中(减去:"node_modules/@clr/icons/clr-icons.min.js"和这个:"node_modules/@webcomponents/custom-elements/custom-elements.min.js",),以确保它们不会引起任何问题。

答案 1 :(得分:1)

ClrIconModule导入您的app.module.ts,或者如果您有特定的模块导入,例如下面的示例。

home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeComponent } from './home.component';
import { RouterModule, Routes } from '@angular/router';
import { ClrIconModule } from '@clr/angular';

const routes: Routes = [
  {
    path: '',
    component: HomeComponent
  }
];

@NgModule({
  declarations: [HomeComponent],
  imports: [CommonModule, RouterModule.forChild(routes), ClrIconModule]
})
export class HomeModule {}

因此您可以在组件中使用<clr-icon>

home.component.html

<div class="main-container">
  <header class="header header-6">
    <div class="branding">
      <clr-icon shape="vm-bug"></clr-icon>
      <span class="title">Project Clarity</span>
    </div>
  </header>
  <div class="content-container">
    <div class="content-area">
      ...
    </div>
    <nav class="sidenav">
      ...
    </nav>
  </div>
</div>