错误:StaticInjectorError(AppModule)[主页 -> 蓝牙串行]

ach*_*d24 3 javascript bluetooth typescript angular ionic4

我在 Ionic 4 应用程序中使用该插件\'@ionic-native/bluetooth-serial/ngx\'与热敏打印机进行通信。如果我使用 android 7.1.1 编译 android 设备的源代码,它会显示以下错误:

\n\n
\n

E/电容器/插件/控制台:错误错误:未捕获(承诺):错误:\n StaticInjectorError(AppModule)[主页 - >蓝牙串行]:\ n StaticInjectorError(平台:核心)[主页 - >蓝牙串行]:\ n NullInjectorError : 没有蓝牙串行的提供程序!\n 错误:StaticInjectorError(AppModule)[主页 -> 蓝牙串行]: \n StaticInjectorError(平台:核心)[主页 -> 蓝牙串行]: \n NullInjectorError: 没有蓝牙串行的提供程序!\n 在 NullInjector。 Push../node_modules/@angular/core/fesm5/core.js.NullInjector.get\n (http://localhost/vendor.js:42939:19)\n 在resolveToken (http://localhost/vendor.get\n) js:43184:24)\n 在 tryResolveToken (http://localhost/vendor.js:43128:16)\n 在 StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get \n (http://localhost/vendor.js:43025:20)\n 在resolveToken (http://localhost/vendor.js:43184:24)\n 在tryResolveToken (http://localhost/vendor.js) :43128:16)\n 在 StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get\n (http://localhost/vendor.js:43025:20)\n 在resolveNgModuleDep (http://localhost/vendor.js:55261:29)\n 位于 NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get\n (http://localhost/ vendor.js:55950:16)\n 在resolveNgModuleDep (http://localhost/vendor.js:55261:29)

\n
\n\n

我只导入了它并在构造函数中添加了参数。

\n\n

home.ts 代码:

\n\n
import { Component } from \'@angular/core\';\nimport { BluetoothSerial } from \'@ionic-native/bluetooth-serial/ngx\';\n\n@Component({\n  selector: \'app-home\',\n  templateUrl: \'home.page.html\',\n  styleUrls: [\'home.page.scss\'],\n})\nexport class HomePage {\n\n  infoText:string = \'\';\n\n  constructor(private bluetoothSerial: BluetoothSerial) {}\n\n  listAllItems()\n  {\n    this.infoText = \'Hier werden alle Ger\xc3\xa4te aufgelistet!!!\';\n  }\n\n  isConnected()\n  {\n    this.infoText = \'Hier wird angezeigt ob es verbunden ist!!!\';\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

有谁知道错误的原因?感谢帮助。

\n

rtp*_*rry 5

除了本机插件页面上的说明之外,每次向项目添加插件时还必须遵循一些常规说明。

它们列在这里:

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

// app.module.ts
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

...

@NgModule({
  ...

  providers: [
    ...
    BluetoothSerial
    ...
  ]
  ...
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)