How to Install ShareThis Module for Your Angular App

By January 11, 2021

We’re happy to announce that ShareThis has built its own module for AngularRS! Follow the directions below to learn how you can install Sharethis inline and sticky share buttons onto your Angular apps/sites.

The Angular module for ShareThis buttons are available within our Git repository, from NPMjs or you can initiate via angular cli. 

  1. Initiate your project (Skip if you already have it). If you don’t have angular cli, you can download it here: https://cli.angular.io/. After downloaded, run the following command to create your project:
    ng new <project-name>
  2. Install sharethis-angular dependency: Go to your project folder:
    cd <project-name>
  3. Run the following command:
    npm i sharethis-angular
  4. Finish installation and add the module: Once you’ve completed installation, go to:
    /<project-name>/src/app/app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SharethisAngularModule } from 'sharethis-angular';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    SharethisAngularModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • You will need to:
    • import SharethisAngularModule from sharethis-angular
    • add SharethisAngularModule to imports

5. Start customizing via components: Now go to
<project-name>/src/app/app.component.ts 


import { Component, OnInit } from '@angular/core';

const InlineShareButtonsConfig = {
  alignment: 'center', // alignment of buttons (left, center, right)
  color: 'social', // set the color of buttons (social, white)
  enabled: true, // show/hide buttons (true, false)
  font_size: 16, // font size for the buttons
  labels: 'cta', // button labels (cta, counts, null)
  language: 'en', // which language to use (see LANGUAGES)
  networks: [
    // which networks to include (see SHARING NETWORKS)
    'whatsapp',
    'linkedin',
    'messenger',
    'facebook',
    'twitter',
  ],
  padding: 12, // padding within buttons (INTEGER)
  radius: 4, // the corner radius on each button (INTEGER)
  show_total: true,
  size: 40, // the size of each button (INTEGER)
  // OPTIONAL PARAMETERS
  url: 'https://www.sharethis.com', // (defaults to current url)
  image: 'https://bit.ly/2CMhCMC', // (defaults to og:image or twitter:image)
  description: 'custom text', // (defaults to og:description or twitter:description)
  title: 'custom title', // (defaults to og:title or twitter:title)
  message: 'custom email text', // (only for email sharing)
  subject: 'custom email subject', // (only for email sharing)
  username: 'custom twitter handle', // (only for twitter sharing)
};

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})

export class AppComponent {
  inlineShareButtonsConfig = InlineShareButtonsConfig;
}

6. Create config for share buttons: Copy the InlineShareButtonsConfig above and create a config. We recommend storing the config in a separate file and import into the component you wish to use. Then all you will need to do is pass it to the component property. 

7. Add code to HTML: Now setup the html, go to:
<project-name>/src/app/app.component.html 
Add the following:

<lib-inline-share-buttons
  [config]="inlineShareButtonsConfig"
></lib-inline-share-buttons>

You can also set up other share buttons like below

<lib-inline-follow-buttons
  [config]="inlineFollowButtonsConfig"
></lib-inline-follow-buttons>

<lib-inline-reaction-buttons
  [config]="inlineReactionButtonsConfig"
></lib-inline-reaction-buttons>

<lib-sticky-share-buttons
  [config]="stickyButtonsConfig"
></lib-sticky-share-buttons>

8. The last step is to run:
ng serve

9. Now view within the browser, go to: http://localhost:4200/ and the buttons should now appear

Need help? Get in touch with us at support@sharethis.com