首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用in 4和ng2-pdf-viewer修复"ERROR Error: Uncaught (in promise):Error: Template parse errors“

如何使用in 4和ng2-pdf-viewer修复"ERROR Error: Uncaught (in promise):Error: Template parse errors“
EN

Stack Overflow用户
提问于 2019-06-07 01:36:54
回答 1查看 1.6K关注 0票数 0

我已经导入了ng2-pdf-viewer并按照示例进行了设置,但是我得到了"ERROR Error: Uncaught (in promise):Error: Template parse error:“错误。

我尝试将导入文件移动到home.ts,但也不起作用。我真的需要弄清楚这件事。

app.module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { PdfViewerModule } from 'ng2-pdf-viewer';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, PdfViewerModule],
  providers: [
    StatusBar,
    SplashScreen,
    PdfViewerModule,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

home.html

代码语言:javascript
复制
<ion-header>
  <ion-toolbar>
    <ion-title>
      NG2-PDF-VIEWER
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <pdf-viewer src="{{pdf}}" original-size="true" show-all="true"></pdf-viewer>
</ion-content>

home.ts

代码语言:javascript
复制
import { Component } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
  providers: [ ]
})
export class HomePage {

  public pdf;
  constructor() {
    this.pdf = 'http://www.axmag.com/download/pdfurl-guide.pdf';
  }

}

这是我得到的完整错误:

代码语言:javascript
复制
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'src' since it isn't a known property of 'pdf-viewer'.
1. If 'pdf-viewer' is an Angular component and it has 'src' input, then verify that it is part of this module.
2. If 'pdf-viewer' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("

<ion-content>
  <pdf-viewer [ERROR ->]src="{{pdf}}" original-size="true" show-all="true"></pdf-viewer>
</ion-content>
"): ng:///HomePageModule/HomePage.html@9:14
'pdf-viewer' is not a known element:
1. If 'pdf-viewer' is an Angular component, then verify that it is part of this module.
2. If 'pdf-viewer' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("

<ion-content>
  [ERROR ->]<pdf-viewer src="{{pdf}}" original-size="true" show-all="true"></pdf-viewer>
</ion-content>
"): ng:///HomePageModule/HomePage.html@9:2
Error: Template parse errors:
Can't bind to 'src' since it isn't a known property of 'pdf-viewer'.
1. If 'pdf-viewer' is an Angular component and it has 'src' input, then verify that it is part of this module.
2. If 'pdf-viewer' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("

<ion-content>
  <pdf-viewer [ERROR ->]src="{{pdf}}" original-size="true" show-all="true"></pdf-viewer>
</ion-content>
"): ng:///HomePageModule/HomePage.html@9:14
'pdf-viewer' is not a known element:
EN

回答 1

Stack Overflow用户

发布于 2019-06-08 00:14:05

您需要将此模块(PDF查看器)准确导入到要使用其组件的模块中。

您可以在app.module.ts中找到它,但是需要通过使用它的模块来导入它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56482556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档