【问题标题】:Ionic blank screen from plugin import插件导入的离子黑屏
【发布时间】:2020-03-06 22:47:46
【问题描述】:

我正在尝试使用 Ionic 和 BluetoothLE 插件构建一个 BLE 配置应用程序。但是,当我导入插件时,它给了我一个空白屏幕。我已经更新到 ionic 5,一切都是最新的。我正在尝试通过 android studio 上的 USB 调试模式来构建它。在我添加导入语句之前它工作正常。

我按照文档中的方式导入它import { BluetoothLE } from '@ionic-native/bluetooth-le/ngx';

插件已正确安装,并被识别为要导入的内容。但由于某种原因,它只会让应用程序变砖。

这是 package-lock.json:

"@ionic-native/bluetooth-le": {
      "version": "5.22.0",
      "resolved": "https://registry.npmjs.org/@ionic-native/bluetooth-le/-/bluetooth-le-5.22.0.tgz",
      "integrity": "sha512-evqUuWzhVZZO7znOQvShCYHP8HdElGwnxpWUCYhSGp0YsoacYJUIB7U4LN0Y7azTn3wgMRWT4m7M49Z42ErMXw==",
      "requires": {
        "@types/cordova": "^0.0.34"
      }

另外,这是插件https://ionicframework.com/docs/native/bluetooth-le

在带有离子服务的浏览器上运行它,我在控制台中收到此错误

  StaticInjectorError(Platform: core)[HomePage -> BluetoothLE]: 
    NullInjectorError: No provider for BluetoothLE!
NullInjectorError: StaticInjectorError(AppModule)[HomePage -> BluetoothLE]: 
  StaticInjectorError(Platform: core)[HomePage -> BluetoothLE]: 
    NullInjectorError: No provider for BluetoothLE!
    at NullInjector.get (core.js:855)
    at resolveToken (core.js:17514)
    at tryResolveToken (core.js:17440)
    at StaticInjector.get (core.js:17266)
    at resolveToken (core.js:17514)
    at tryResolveToken (core.js:17440)
    at StaticInjector.get (core.js:17266)
    at resolveNgModuleDep (core.js:30393)
    at NgModuleRef_.get (core.js:31578)
    at resolveNgModuleDep (core.js:30393)
    at resolvePromise (zone-evergreen.js:797)
    at resolvePromise (zone-evergreen.js:754)
    at zone-evergreen.js:858
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:39680)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)
    at Zone.runTask (zone-evergreen.js:168)
    at drainMicroTaskQueue (zone-evergreen.js:559)```

【问题讨论】:

  • 你们还想知道什么?这是一个我知之甚少的问题,所以除了我所知道的导致插件导入问题之外,我不确定从哪里开始。

标签: angular ionic-framework bluetooth-lowenergy capacitor


【解决方案1】:

在我能找到的任何地方都没有记录。也许那是因为我是 Ionic 的新手,这是常识(我觉得软件中这样的任何事情都不应该被视为常识)但是在使用插件时,您需要将插件导入 app.module.ts 和像这样在提供者下添加它:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { BluetoothLE } from '@ionic-native/bluetooth-le/ngx';

import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    BluetoothLE
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多