首页 > 解决方案 > 尽管导入了模块并包含 CUSTOM_ELEMENTS_SCHEMA 模式,但组件不是已知元素

问题描述

PinchZoom 是ngx-pinch-zoom我在 Angular 6 项目中安装的一个节点模块。值得注意的是,它也是一个 ionic 4 项目。

在我的 app.module.ts 中,我已导入PinchZoomModule并包含CUSTOM_ELEMENTS_SCHEMA在我的架构中。

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { PinchZoomModule } from 'ngx-pinch-zoom';

@NgModule({
  declarations: [
    AppComponent
  ],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
  entryComponents: [],
  exports: [],
  imports: [
    BrowserModule,
    AppRoutingModule,
    PinchZoomModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

在一个页面中,我添加了正确的代码来使用 PinchZoom 功能:

<pinch-zoom>
    <img class="question-image" [src]="myImageUrl" />
</pinch-zoom>

但是,当我运行我的应用程序时,出现以下错误:

'pinch-zoom' is not a known element:
1. If 'pinch-zoom' is an Angular component, then verify that it is part of this module.
2. If 'pinch-zoom' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("ss="ion-padding no-bottom-padding">
        [ERROR ->]<pinch-zoom>

标签: javascriptnode.jsangulartypescriptecmascript-6

解决方案


您当前使用的是哪个组件 pinch-zoom ?

如果要导入PinchZoomModule,则必须将使用该标签的组件也导入到导入的模块中PinchZoomModule

如果您在<pinch-zoom>多个模块中使用标签,请考虑将其移至导入的一个共享模块PinchZoomModule


推荐阅读