首页 > 解决方案 > cordova-plugin-inappbrowser 不能从角度工作

问题描述

我试图打开 pdf 一个通过 api 从 angular cordova 应用程序接收到的文件。

this.laccountservice.downloadPDF(order).subscribe(
      (res) => {
      var files=  new Blob([res], { type: 'application/pdf' })
        console.log(files)
      var fileURL = URL.createObjectURL(files);
      //window.open(fileURL); // if you want to open it in new tab
     cordova.InAppBrowser.open(fileURL, '_blank', 'location=yes');

如何定义科尔多瓦?从“cordova-plugin-inappbrowser”导入{}?我没有使用phonegap cordova的离子简单角度应用程序

标签: angulartypescriptcordova

解决方案


您可以使用cordova instance以下方式

(window as any).cordova.InAppBrowser.open(fileURL, '_blank', 'location=yes');

或者

import { Component } from '@angular/core';

declare var cordova:any;

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})

export class AppComponent  {

  constructor() {
    cordova.InAppBrowser.open(fileURL, '_blank', 'location=yes');
  }

}

推荐阅读