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();
}
}
每當我點擊一個打印按鈕,沒有任何反應!
有沒有人有這種插件的麻煩?我做錯什麼了嗎 ?我應該安裝其他的東西來解決這個問題嗎?有沒有人有一個例子項目運作良好?
非常感謝!