hanatharesh2712 / ionic-native-sms-retriever-plugin-master

Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
27 stars 18 forks source link

Plugin not working for IONIC5, throwing "NullInjectorError: No provider for SmsRetriever!" #29

Closed RajivCodeLab closed 3 years ago

RajivCodeLab commented 3 years ago

Hi Team,

This plugin is not working on IONIC5 if directly added into page.ts file also not working if I registered inside app.module.ts, getting below error.

NullInjectorError: No provider for SmsRetriever! NullInjectorError: R3InjectorError(BookAppointmentPageModule)[SmsRetriever -> SmsRetriever -> SmsRetriever -> SmsRetriever]: NullInjectorError: No provider for SmsRetriever!

I tried adding in app.module.ts but after that, it's throwing

Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType (core.js:36241) at core.js:36259 at Array.forEach () at registerNgModuleType (core.js:36255) at new NgModuleFactory$1 (core.js:36420) at compileNgModuleFactoryPOST_R3 (core.js:42309) at PlatformRef.bootstrapModule (core.js:42676) at Module../src/main.ts (main.ts:11) at webpack_require (bootstrap:84) at Object.0 (main.ts:12)

Find below the code FYR.

import { SmsRetriever } from '@ionic-native/sms-retriever/ngx'; @NgModule({ declarations: [AppComponent, NotificationModalComponent, AlertModalComponent], entryComponents: [NotificationModalComponent,AlertModalComponent], imports: [ BrowserModule, IonicModule.forRoot(), AppRoutingModule, NgbModule, HttpClientModule, CommonHeaderModule,

hanatharesh2712 commented 3 years ago

@devrajeev Please take a look at a working example for Ionic 4. It is the same for Ionic 5. It seems you are missing the Provider section in app.module.ts

providers: [
    StatusBar,
    SplashScreen,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
   SmsRetriever <-- Add this in Providers
  ],

https://github.com/hanatharesh2712/sms-plugin-test

RajivCodeLab commented 3 years ago

Thanks for the quick reply, I did that too,

please check below same mentioned above.

Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType (core.js:36241) at core.js:36259 at Array.forEach () at registerNgModuleType (core.js:36255) at new NgModuleFactory$1 (core.js:36420) at compileNgModuleFactory__POST_R3__ (core.js:42309) at PlatformRef.bootstrapModule (core.js:42676) at Module../src/main.ts (main.ts:11) at webpack_require (bootstrap:84) at Object.0 (main.ts:12)

hanatharesh2712 commented 3 years ago

Please send your git repo here. so, I can take a look and check what is creating an issue. or what is written in your main.ts file.? Thanks

hanatharesh2712 commented 3 years ago

@devrajeev You can find this repo for Working example of the plugin with Ionic 5: https://github.com/hanatharesh2712/sms-plugin-test-ionic-5