我在我的Ionic 4应用程序中使用插件'@ionic-native/bluetooth-serial/ngx'
与热打印机进行通信。如果我用Android7.1.1编译android设备的源代码,它将显示以下错误:
E/电容/插件/控制台:错误:未知(承诺):错误: StaticInjectorError(AppModule)HomePage -> BluetoothSerial: StaticInjectorError(平台:核)HomePage -> BluetoothSerial: NullInjectorError:无BluetoothSerial提供程序!错误: StaticInjectorError(AppModule)HomePage -> BluetoothSerial: StaticInjectorError(平台:核心)HomePage -> BluetoothSerial: NullInjectorError:无BluetoothSerial提供程序!在NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (http: //localhost/vendor.js:42939:19),resolveToken (http: //localhost/vendor.js:43184:24),tryResolveToken (http: //localhost/vendor.js:43128:16)http: //localhost/vendor.js:43025:20 StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (http: //localhost/vendor.js:43025:20) resolveToken (http: //localhost/vendor.js:43184:24) tryResolveToken (http: //localhost/vendor.js:43128:16) (http: //localhost/vendor.js:43025:20)/localhost/vendor.js:55261:29) NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (http: //localhost/vendor.js:55950:16),resolveNgModuleDep (http: //localhost/vendor.js:55261:29)
我只导入了它并在构造函数中添加了参数。
home.ts代码:
import { Component } from '@angular/core';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
infoText:string = '';
constructor(private bluetoothSerial: BluetoothSerial) {}
listAllItems()
{
this.infoText = 'Hier werden alle Geräte aufgelistet!!!';
}
isConnected()
{
this.infoText = 'Hier wird angezeigt ob es verbunden ist!!!';
}
}
有人知道错误的原因吗?谢谢你帮忙。
发布于 2019-07-06 01:31:29
除了本机插件页面上的说明外,还有一些一般性说明,您每次向项目中添加插件时都必须遵循这些说明。
它们列于此:
这意味着您需要编辑app.module.ts以将模块导入到项目中。然后应用程序的其余部分就可以使用它了。
// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';
...
@NgModule({
...
providers: [
...
BluetoothSerial
...
]
...
})
export class AppModule { }
https://stackoverflow.com/questions/56902037
复制相似问题