2017-11-11 111 views
0

我已经使用@离子本机/打印机插件来实现账单报告的打印选项。@离子本机/打印机不工作

我已经使用这个命令行安装的插件:

npm install --save @ionic-native/printer 

然后在viewbill.html我把一条线,积极打印机:

<button ion-button (click)="print()"> 
    <ion-icon name="print"> 
     </ion-icon> 
     Print 
    </button> 

然后我viewbill.ts代码:

import { Component } from '@angular/core'; 
import { IonicPage, NavController, NavParams, Platform, AlertController } from 'ionic-angular'; 
import { Printer, PrintOptions } from '@ionic-native/printer'; 

@IonicPage() 
@Component({ 
    selector: 'page-viewbill', 
    templateUrl: 'viewbill.html', 
}) 
export class ViewbillPage { 

    public srNo = []; 
    public particulars = []; 
    public particularAmt = []; 
    constructor(public navCtrl: NavController, 
       public navParams: NavParams, 
       public printer: Printer, 
       public platform: Platform, 
       public alertCtrl: AlertController) { 
    } 

    ionViewDidLoad() { 
    console.log('ionViewDidLoad ViewbillPage'); 
    this.srNo = [ 
     {no: '1'}, 
     {no: '2'}, 
     {no: '3'} 
    ]; 

    this.particulars = [ 
     {particular: 'Particular 1'}, 
     {particular: 'Particular 2'}, 
     {particular: 'Particular 3'} 
    ]; 

    this.particularAmt = [ 
     {amount: '100'}, 
     {amount: '500'}, 
     {amount: '1000'} 
    ]; 
    } 

    print(){ 
    if(this.platform.is('cordova')){ 
     if(this.printer.isAvailable()) 
     { 
     let options: PrintOptions = { 
      name: 'Bill Report', 
      duplex: true, 
      landscape: true, 
      grayscale: true 
     }; 
     var page = document.getElementById('billReport'); 
     this.printer.print(page, options); 
     } 
     else{ 
     this.alert('Please connect your device to a printer!'); 
     } 
    } 
    else{ 
     this.alert('You are on a web browser!'); 
    } 
    } 

    alert(message: string) { 
    this.alertCtrl.create({ 
     title: 'Info!', 
     subTitle: message, 
     buttons: ['OK'] 
    }).present(); 
    } 
} 

每当我点击一个打印按钮,没有任何反应!

有没有人有这种插件的麻烦?我做错什么了吗 ?我应该安装其他的东西来解决这个问题吗?有没有人有一个例子项目运作良好?

非常感谢!

回答

0

你似乎已经错过了安装插件codrova的步骤:

ionic cordova plugin add de.appplant.cordova.plugin.printer 

离子本地包是上述插件的包装。检查文档here