简体   繁体   English

在 angular 项目中使用 GoogleChromeLabs pinch-zoom

[英]Using GoogleChromeLabs pinch-zoom in a angular project

I just started learning angular and I'm working on a project in which I want to add a pinch-zoom functionality.我刚开始学习 angular 并且我正在做一个项目,我想在其中添加捏缩放功能。 I found this library on github https://github.com/GoogleChromeLabs/pinch-zoom and I figured it is a perfect fit for my needs.我在 github https://github.com/GoogleChromeLabs/pinch-zoom上找到了这个库,我认为它非常适合我的需求。 As I am new to angular and front end technologies in general, so I need some help in setting it up.由于我是 angular 和一般前端技术的新手,所以我需要一些帮助来设置它。 I have run the following command to install the package npm install --save-dev pinch-zoom-element (as per the readme file).我已经运行以下命令来安装 package npm install --save-dev pinch-zoom-element (根据自述文件)。 I want to use it in a component html to be able to zoom in on a canvas.我想在 html 组件中使用它,以便能够放大 canvas。

<pinch-zoom>
  <canvas id="imageStream" width="320" height="240"></canvas>
</pinch-zoom>

But ehn building the project ( npm run build ) I get the following errors:但是 ehn 构建项目( npm run build )我收到以下错误:

ERROR in '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. ("
</ion-item>

[ERROR ->]<pinch-zoom>
  <canvas id="<imageStream" width="320" height="240"></canvas>
</pinch-zoom>
")

My componenent's .spec.ts file contains the CUSTOM_ELEMENTS_SCHEMA我的组件的.spec.ts文件包含CUSTOM_ELEMENTS_SCHEMA

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ImageStreamComponent } from './image-stream.component';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

describe('ImageStreamComponent', () => {
  let component: ImageStreamComponent;
  let fixture: ComponentFixture<ImageStreamComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ImageStreamComponent ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA],
      providers: [
        { }
      ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ImageStreamComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

I also tried importing the module where I am using it, in the component's .ts file我还尝试在组件的.ts文件中导入我正在使用的模块

import { PinchZoom } from 'pinch-zoom-element';

But I get the same errors when building the project with this additional one:但是在使用这个额外的项目构建项目时,我遇到了同样的错误:

error TS2305: Module '"../../../node_modules/pinch-zoom-element/dist"' has no exported member 'PinchZoom'.

12 import { PinchZoom } from 'pinch-zoom-element';

I find this weird because if you look in the package source files you see the class exported with that name.我觉得这很奇怪,因为如果您查看 package 源文件,您会看到使用该名称导出的 class。 Any feedback would be greatly appreciated!任何反馈将不胜感激!

If 'pinch-zoom' is a Web Component如果“pinch-zoom”是 Web 组件

and this is the case就是这样

then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.然后将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。

You should add this to the .module.ts file where you have declared your component, not in the .spec.ts file.您应该将其添加到声明组件的.module.ts文件中,而不是.spec.ts文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM