So installieren Sie das Modul ShareThis für Ihre Angular-App

Wir freuen uns, Ihnen mitteilen zu können, dass ShareThis sein eigenes Modul für Angular entwickelt hat! Folgen Sie den Anweisungen unten, um zu erfahren, wie Sie ShareThis Inline und Sticky Share Buttons auf Ihren Angular-Apps/Sites installieren können.

Das Angular-Modul für ShareThis Buttons ist in unserer Git-Repository, von NPMjs oder Sie können über Angular CLI initiieren. 

Hinweis: Ihre Angular-Version sollte mindestens 14.1.0 sein, damit das Modul kompatibel ist.

  1. Initiieren Sie Ihr Projekt (Überspringen Sie es, wenn Sie es bereits haben). Wenn Sie Angular Cli nicht haben, können Sie es hier herunterladen: https://cli.angular.io/. Nach dem Herunterladen führen Sie den folgenden Befehl aus, um Ihr Projekt zu erstellen:
    ng new
  2. Installieren Sie die sharethis-angular-Abhängigkeit: Gehen Sie in Ihren Projektordner:
    cd
  3. Führen Sie den folgenden Befehl aus:
    npm i sharethis-angular
  4. Beenden Sie die Installation und fügen Sie das Modul hinzu: Wenn Sie die Installation abgeschlossen haben, gehen Sie zu:
    //src/app/app.module.ts
  • Das müssen Sie tun:
  • import { SharethisAngularModule } from 'sharethis-angular';

  • und fügen Sie SharethisAngularModule zu den Importen hinzu
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. Starten Sie das Customizing über Komponenten: Gehen Sie nun zu
/src/app/app.component.ts 

6. Erstellen Sie die Konfiguration für die Share-Buttons: Kopieren Sie die InlineShareButtonsConfig unten und erstellen Sie eine Konfiguration (siehe Konfigurationen der anderen Tasten). Wir empfehlen, die Konfiguration in einer separaten Datei zu speichern und in die Komponente zu importieren, die Sie verwenden möchten. Dann brauchen Sie sie nur noch an die Komponenteneigenschaft zu übergeben. 

Hinweis

Die Anzahl der Freigaben ist mit der URL verknüpft. Wenn in den Konfigurationsattributen keine URL angegeben ist, wird die URL verwendet, unter der sich die Schaltflächen befinden. Denken Sie daran, die URL im folgenden Beispiel anzupassen oder zu entfernen.


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. Code zu HTML hinzufügen: Richten Sie nun den HTML-Code ein, gehen Sie zu:
/src/app/app.component.html 
Fügen Sie Folgendes hinzu:

 

Sie können auch andere Freigabe-Schaltflächen einrichten:




    
 

8. Der letzte Schritt ist der Lauf:
ng serve

9. Rufen Sie nun im Browser die Seite http://localhost:4200/ und die Schaltflächen sollten nun erscheinen.


Außerdem finden Sie hier die Konfigurationen für unsere anderen Schaltflächen:


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

Netzwerke freigeben

Netzwerken folgen

Reaktionsschaltflächen