首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >错误: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]

错误: StaticInjectorError(AppModule)[HomePage -> BluetoothSerial]
EN

Stack Overflow用户
提问于 2019-07-05 03:17:34
回答 1查看 1.6K关注 0票数 3

我在我的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代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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!!!';
  }
}

有人知道错误的原因吗?谢谢你帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-06 01:31:29

除了本机插件页面上的说明外,还有一些一般性说明,您每次向项目中添加插件时都必须遵循这些说明。

它们列于此:

这意味着您需要编辑app.module.ts以将模块导入到项目中。然后应用程序的其余部分就可以使用它了。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

...

@NgModule({
  ...

  providers: [
    ...
    BluetoothSerial
    ...
  ]
  ...
})
export class AppModule { }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56902037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文