How to Install ShareThis Module for Your Angular App

We’re happy to announce that ShareThis has built its own module for Angular! 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 is available within our Git repository, from NPMjs or you can initiate via Angular CLI. 

Note: Your Angular version should be at least 14.1.0 for the module to be compatible.

  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 downloading, 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
  • You will need to:
  • import { SharethisAngularModule } from 'sharethis-angular';

  • and add SharethisAngularModule to imports
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 { }

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

6. Create config for share buttons: Copy the InlineShareButtonsConfig below and create a config (see other buttons’ configurations). 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. 

Note

The Share Count is linked to the URL, if no URL is provided in the configuration attributes, it will use the URL where the buttons are located. Remember to customize or remove the URL in the example below.


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;
}

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

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

You can also set up other share buttons:

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

<st-inline-reaction-buttons [config]="inlineReactionButtonsConfig"></st-inline-reaction-buttons>
    
<st-sticky-share-buttons [config]="stickyShareButtonsConfig"></st-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.


Additionally, here are the configurations for our other buttons:


//Sticky Share Buttons

const stickyShareButtonsConfig: StickyShareButtonsConfig={
            alignment: 'left',    // alignment of buttons (left, 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
            hide_desktop: false,  // hide buttons on desktop (true, false)
            labels: 'counts',     // button labels (cta, counts, null)
            language: 'en',       // which language to use (see LANGUAGES)
            min_count: 0,         // hide react counts less than min_count (INTEGER)
            networks: [           // which networks to include (see SHARING NETWORKS)
              'linkedin',
              'facebook',
              'twitter',
              'pinterest',
              'email'
            ],
            padding: 12,          // padding within buttons (INTEGER)
            radius: 4,            // the corner radius on each button (INTEGER)
            show_total: true,     // show/hide the total share count (true, false)
            show_mobile: true,    // show/hide the buttons on mobile (true, false)
            show_toggle: true,    // show/hide the toggle buttons (true, false)
            size: 48,             // the size of each button (INTEGER)
            top: 160,             // offset in pixels from the top of the page


            // 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)
};

// Inline Follow Buttons

const inlineFollowButtonsConfig: InlineFollowButtonsConfig = {
            action: 'Follow us:', // call to action (STRING)
            action_enabled: true,  // show/hide call to action (true, false)
            action_pos: 'bottom', // position of call to action (left, top, right)
            alignment: 'center',  // alignment of buttons (left, center, right)
            color: 'white',       // set the color of buttons (social, white)
            enabled: true,        // show/hide buttons (true, false)
            networks: [           // which networks to include (see FOLLOW NETWORKS)
              'twitter',
              'facebook',
              'instagram',
              'youtube'
            ],
            padding: 8,           // padding within buttons (INTEGER)
            profiles: {           // social profile links for buttons
              twitter: 'sharethis',
              facebook: 'sharethis',
              instagram: 'sharethis',
              youtube: '/channel/UCbM93niCmdc2RD9RZbLMP6A?view_as=subscriber'
            },
            radius: 9,            // the corner radius on each button (INTEGER)
            size: 32,             // the size of each button (INTEGER)
            spacing: 8            // the spacing between buttons (INTEGER)
};

// Inline Reaction Buttons

const inlineReactionButtonsConfig: InlineReactionButtonsConfig = {
            alignment: 'center',  // alignment of buttons (left, center, right)
            enabled: true,        // show/hide buttons (true, false)
            language: 'en',       // which language to use (see LANGUAGES)
            min_count: 0,         // hide react counts less than min_count (INTEGER)
            padding: 12,          // padding within buttons (INTEGER)
            reactions: [          // which reactions to include (see REACTIONS)
              'slight_smile',
              'heart_eyes',
              'laughing',
              'astonished',
              'sob',
              'rage'
            ],
            size: 48,             // the size of each button (INTEGER)
            spacing: 8,           // the spacing between buttons (INTEGER)

            // OPTIONAL PARAMETERS

            url: 'https://www.sharethis.com' // (defaults to current url)
};

Sharing Networks

Follow Networks

Reaction Buttons