IONIC 4 Social Share don`t function

Using default configuration have Erro

Does anyone have an example?

What error does it indicate?
Which methods are you using?

import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FavoritoService } from 'src/app/services/favorito/favorito.service';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';

@Component({
  selector: 'app-details',
  templateUrl: './details.page.html',
  styleUrls: ['./details.page.scss'],
})
export class DetailsPage {

  public conveniado: any;

  constructor(
    private route: ActivatedRoute,
    private router: Router,
    private favoritoService: FavoritoService,
    private socialSharing: SocialSharing) {

    this.route.queryParams.subscribe(params => {
      if (this.router.getCurrentNavigation().extras.state) {
        this.conveniado = this.router.getCurrentNavigation().extras.state.conveniado;
      }
    });

  }

  share() {
    console.log('Vamos compartilhar!!');
    this.socialSharing.canShareViaEmail().then(() => {
      // Sharing via email is possible
    }).catch(() => {
      // Sharing via email is not possible
    });
  }

My ionic info:

Ionic:

ionic (Ionic CLI) : 4.6.0 (/home/agriness/node_modules/ionic)
Ionic Framework : @ionic/angular 4.1.2
@angular-devkit/build-angular : 0.13.7
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.7
@ionic/angular-toolkit : 1.4.1

Cordova:

cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 5 other plugins)

System:

Android SDK Tools : 26.1.1 (/home/agriness/Android/Sdk)
NodeJS : v10.15.0 (/usr/local/bin/node)
npm : 6.7.0
OS : Linux 4.15

Post your error message, it will be hard to know what is happening without it.

vendor.js:49767 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[DetailsPage -> SocialSharing]:
StaticInjectorError(Platform: core)[DetailsPage -> SocialSharing]:
NullInjectorError: No provider for SocialSharing!
Error: StaticInjectorError(AppModule)[DetailsPage -> SocialSharing]:
StaticInjectorError(Platform: core)[DetailsPage -> SocialSharing]:
NullInjectorError: No provider for SocialSharing!
at NullInjector.push…/node_modules/@angular/core/fesm5/core.js.NullInjector.get (vendor.js:42939)
at resolveToken (vendor.js:43184)
at tryResolveToken (vendor.js:43128)
at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:43025)
at resolveToken (vendor.js:43184)
at tryResolveToken (vendor.js:43128)
at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:43025)
at resolveNgModuleDep (vendor.js:55261)
at NgModuleRef_.push…/node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:55950)
at resolveNgModuleDep (vendor.js:55261)
at NullInjector.push…/node_modules/@angular/core/fesm5/core.js.NullInjector.get (vendor.js:42939)
at resolveToken (vendor.js:43184)
at tryResolveToken (vendor.js:43128)
at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:43025)
at resolveToken (vendor.js:43184)
at tryResolveToken (vendor.js:43128)
at StaticInjector.push…/node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:43025)
at resolveNgModuleDep (vendor.js:55261)
at NgModuleRef_.push…/node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:55950)
at resolveNgModuleDep (vendor.js:55261)
at resolvePromise (polyfills.js:3189)
at resolvePromise (polyfills.js:3146)
at polyfills.js:3250
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2781)
at Object.onInvokeTask (vendor.js:51333)
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2780)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:2553)
at drainMicroTaskQueue (polyfills.js:2959)
at ZoneTask.push…/node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (polyfills.js:2860)
at invokeTask (polyfills.js:4102)
defaultErrorLogger @ vendor.js:49767
push…/node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ vendor.js:49815
next @ vendor.js:51814
schedulerFn @ vendor.js:47558
push…/node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ vendor.js:111627
push…/node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ vendor.js:111565
push…/node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ vendor.js:111508
push…/node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ vendor.js:111485
push…/node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ vendor.js:111250
push…/node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ vendor.js:47542
(anonymous) @ vendor.js:51364
push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ polyfills.js:2749
push…/node_modules/zone.js/dist/zone.js.Zone.run @ polyfills.js:2508
push…/node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ vendor.js:51301
onHandleError @ vendor.js:51364
push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ polyfills.js:2753
push…/node_modules/zone.js/dist/zone.js.Zone.runGuarded @ polyfills.js:2522
_loop_1 @ polyfills.js:3052
api.microtaskDrainDone @ polyfills.js:3061
drainMicroTaskQueue @ polyfills.js:2966
push…/node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ polyfills.js:2860
invokeTask @ polyfills.js:4102
globalZoneAwareCallback @ polyfills.js:4128

Did you import and declare SocialSharing module into app.module.ts?

You need to add the plugin(I mean the module) in app.module.ts in the providers array. After that, do an ionic serve again and the error would probably go. It happened with me quite a few times and doing an ionic serve again fixed it for me.

1 Like

I`m fixed add SocialShare in Provider Array . Thank you for your help .

1 Like