javascript - モジュールをインポートし、CUSTOM_ELEMENTS_SCHEMA スキーマを含めても、コンポーネントが既知の要素として認識されません
PinchZoomは、私がAngular 6プロジェクトにインストールしたノードモジュールngx-pinch-zoomです。なお、これが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>
回答 #1
現在どのコンポーネントでピンチズームを使用していますか?
もし PinchZoomModule をインポートする場合、そのタグを使用しているコンポーネントも PinchZoomModule をインポートするモジュールにインポートする必要があります
複数のモジュールで<pinch-zoom>タグを使用している場合は、PinchZoomModuleをインポートする共有モジュールに移動することを検討してください