离子本机打印机插件不起作用 [英] Ionic native Printer plugin not working
问题描述
(离子 2)位于此处的插件在 android 和 ios 上似乎对我不起作用:http://ionicframework.com/文档/本机/打印机/
(Ionic 2) The plugin located here seems to not work for me on android and ios : http://ionicframework.com/docs/native/printer/
我认为我遵循了这个页面的指导方针,代码正在两个平台上构建,但我在 ios 上出现黑屏,在 android 上模拟时出现空白...
I think that I followed the guidelines from this page, the code is building on both platforms but I got a black screen on ios and a blank one on android when emulate ...
首先我开始了一个新项目:ionic start PrinterApp --v2
First I started a new project : ionic start PrinterApp --v2
然后我安装了平台:android 6.2.1, ios 4.3.1
然后是插件页面的两个命令行:
Then the two command lines from the plugin page :
ionic plugin add --save de.appplant.cordova.plugin.printer
npm install --save @ionic-native/printer
然后在 home.html 中添加一行来激活打印机:
Then in the home.html I put a line to active the printer :
<button class="button" (click)="print()">Print</button>
最后我的 home.ts 看起来像这样:
And finally my home.ts looks like this :
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Printer, PrintOptions } from '@ionic-native/printer';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController, private printer: Printer) {
}
print() {
this.printer.isAvailable();
let options: PrintOptions = {
name: 'MyDocument',
duplex: true,
landscape: true,
grayscale: true
};
this.printer.print("http://google.com", options);
}
}
有没有人遇到过这种插件的问题?我做错什么了吗 ?我应该安装其他东西来解决问题吗?有没有人有一个运行良好的示例项目?
Did anyone have this kind of troubles with the plugin ? Did I do something wrong ? Should I install other things to fix the problem ? And did anyone have a exemple project working well ?
非常感谢!
推荐答案
在 Suraj 和 Gabriel 的帮助下,我设法解决了这个问题,我需要去这个页面获取信息:http://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module
With the help of Suraj and Gabriel I managed to fix the problem, I needed to go to this page to get informations : http://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module
所以输入这一行:npm install @ionic-native/core --save
And so typing this line : npm install @ionic-native/core --save
然后进入我的 App.Module.ts 添加打印机提供程序,如下所示:
Then into my App.Module.ts adding printer provider like this :
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Printer, PrintOptions } from '@ionic-native/printer';
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
providers: [
StatusBar,
SplashScreen,
Printer,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
再次感谢!祝你有美好的一天
Thanks again ! Have a great day
这篇关于离子本机打印机插件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!