This is the documentation for ngx-sharebuttons version 5.x (Angular >= 5)
- For ngx-sharebuttons version 4.x (Angular >= 5), See this documentation
- For ngx-sharebuttons version 3.x (Angular 2 & 4), See this documentation
- Live demo | stackblitz
- Packages
- Share button directive
- Single share button component
- Share buttons component
- Global options
- Styling guide
- Sharing on native apps
- FAQ
- Issues
- License
- Support
- Author
- More plugins
Facebook, Twitter, Google+, LinkedIn, Pinterest, WhatsApp, Messenger, Reddit, Tumblr, Telegram, Email, SMS, VK, StumbleUpOn, Xing, Copy link and Print
The plugin is divided into 3 modules to make it possible to include only the stuff you use.
- @ngx-share/core - Share button directive to convert any element to a share button.
- @ngx-share/button - Share button component to add buttons individually.
- @ngx-share/buttons - Share buttons component to add a collection of share buttons.
Convert any element to a share button using [shareButton] directive.
NPM
$ npm i -S @ngx-share/core
$ npm i -S @fortawesome/{free-solid-svg-icons,free-brands-svg-icons}YARN
$ yarn add @ngx-share/core
$ yarn add @fortawesome/{free-solid-svg-icons,free-brands-svg-icons}Import ShareModule in your module
import { ShareModule } from '@ngx-share/core';
@NgModule({
  imports: [
    HttpClientModule,      // (Required) for share counts
    HttpClientJsonpModule, // (Optional) for Tumblr counts
    ShareModule.forRoot()
  ]
})The most basic usage to create a share button is shareButton={{buttonName}} on a button
<button shareButton="facebook">Share</button>
<button shareButton="twitter">Tweet</button>
<button shareButton="pinterest">Pin</button>To use the default icons and colors, Inject ShareButtons service in your component then access the properties from the template
Component:
import { ShareButtons } from '@ngx-share/core';
@Component({
  // ...
})
export class MyComponent {
  constructor(public share: ShareButtons) {
  }
}Template:
<!--Set color and icon-->
<button shareButton="twitter" [style.backgroundColor]="share.prop.twitter.color">
  <fa-icon [icon]="share.prop.twitter.icon" size="lg"></fa-icon>
</button>
<!--Material example-->
<button md-icon-button shareButton="telegram" [style.color]="share.prop.telegram.color">
  <fa-icon [icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>Check ShareButton Directive Demo.
| Name | Default value | Description | 
|---|---|---|
| [shareButton] | null | Button name, e.g. 'facebook', 'twitter' ...etc. | 
| [url] | current URL | Sharing link. | 
| [title] | null | Override title meta tag for LinkedIn, Reddit and Email. | 
| [description] | null | Override description meta tag for LinkedIn, WhatsApp, Messenger, Telegram, Pinterest and Email | 
| [image] | null | Override image meta tag for Pinterest only. | 
| [tags] | null | Override tags for Tumblr and Twitter. | 
| [autoSetMeta] | true | Auto set meta tags inputs from the SEO meta tags. | 
| [getCount] | false | Gets and emits share counts. | 
| (opened) | button name | Stream that emits when share window has opened. | 
| (closed) | button name | Stream that emits when share dialog has closed. | 
| (count) | share count | Stream that emits share count of the share URL. | 
Use <share-button> component to add share buttons individually.
NPM
$ npm i -S @ngx-share/{core,button}
$ npm i -S @fortawesome/{fontawesome-svg-core,angular-fontawesome,free-solid-svg-icons,free-brands-svg-icons}YARN
$ yarn add @ngx-share/{core,button}
$ yarn add @fortawesome/{fontawesome-svg-core,angular-fontawesome,free-solid-svg-icons,free-brands-svg-icons}Import ShareButtonModule in your module
import { ShareButtonModule } from '@ngx-share/button';
@NgModule({
  imports: [
    HttpClientModule,      // (Required) for share counts
    HttpClientJsonpModule, // (Optional) For Tumblr counts
    ShareButtonModule.forRoot()
  ]
})Import core styles and theme from the global style src/styles.scss
@import '~@ngx-share/button/styles/share-buttons';
@import '~@ngx-share/button/styles/themes/default/default-theme';Check all themes here
Now you can use the component in your template
<share-button button="facebook"></share-button>
<share-button button="twitter"></share-button>Check ShareButton Component Demo.
| Name | Default value | Description | 
|---|---|---|
| [button] | null | Button name, e.g. 'facebook', 'twitter' ...etc. | 
| [theme] | null | Set button theme. | 
| [text] | null | Custom button text. | 
| [icon] | null | Custom button icon. | 
| [size] | 0 | Button size, e.g. -4, 2.5, 1...etc. | 
| [url] | current URL | Sharing link. | 
| [title] | null | Override title meta tag for LinkedIn, Reddit and Email. | 
| [description] | null | Override description meta tag for LinkedIn, WhatsApp, Messenger, Telegram, Pinterest and Email | 
| [image] | null | Override image meta tag for Pinterest only. | 
| [tags] | null | Override tags for Tumblr and Twitter. | 
| [autoSetMeta] | true | Initializes meta tags inputs from the SEO meta tags. | 
| [showIcon] | true | Show button icon. | 
| [showText] | false | Show button text. | 
| [showCount] | false | Show share count. | 
| (opened) | button name | Stream that emits when share dialog has opened. | 
| (closed) | button name | Stream that emits when share dialog has closed. | 
| (count) | share count | Stream that emits share count of the share URL. | 
Use <share-buttons> to add a collection of share buttons.
NPM
$ npm i -S @ngx-share/{core,button,buttons}
$ npm i -S @fortawesome/{fontawesome-svg-core,angular-fontawesome,free-solid-svg-icons,free-brands-svg-icons}YARN
$ yarn add @ngx-share/{core,button,buttons}
$ yarn add @fortawesome/{fontawesome-svg-core,angular-fontawesome,free-solid-svg-icons,free-brands-svg-icons}Import ShareButtonModule in your module
import { ShareButtonModule } from '@ngx-share/button';
@NgModule({
  imports: [
    HttpClientModule,      // (Required) for share counts
    HttpClientJsonpModule, // (Optional) for Tumblr counts
    ShareButtonModule.forRoot()
  ]
})Import icons, core styles and theme from the global style src/styles.scss
@import '~@ngx-share/button/styles/share-buttons';
@import '~@ngx-share/button/styles/themes/default/default-theme';Check all themes
Now you can use the component in your template
<share-buttons></share-buttons>Check ShareButtons Component Demo
| Name | Default value | Description | 
|---|---|---|
| [include] | [ ] | Include certain buttons. Button's order will be as you type it. | 
| [exclude] | [ ] | Exclude certain buttons. | 
| [show] | null | Number of buttons to show, if defined 'more' button will appear. | 
| [theme] | null | Set button theme. | 
| [size] | 0 | Button size, e.g. -4, 2.5, 1...etc. | 
| [url] | current URL | Sharing link. | 
| [title] | null | Override title meta tag for LinkedIn, Reddit and Email. | 
| [description] | null | Override description meta tag for LinkedIn, WhatsApp, Messenger, Telegram, Pinterest and Email | 
| [image] | null | Override image meta tag for Pinterest only. | 
| [tags] | null | Override tags for Tumblr and Twitter. | 
| [autoSetMeta] | true | Initializes meta tags inputs from the SEO meta tags. | 
| [showIcon] | true | Show button icon. | 
| [showText] | false | Show button text. | 
| [showCount] | false | Show share count. | 
| (opened) | button name | Stream that emits when share dialog has opened. | 
| (closed) | button name | Stream that emits when share dialog has closed. | 
| (count) | share count | Stream that emits the share count of the URL. | 
If you want set custom global options, pass your config in the library is imported
import { ShareButtonsOptions } from '@ngx-share/core';
import { ShareButtonsModule } from '@ngx-share/buttons';
const customOptions: ShareButtonsOptions = {
  include: ['facebook', 'twitter', 'google'],
  exclude: ['tumblr', 'stumble', 'vk'],
  theme: 'modern-light',
  gaTracking: true,
  twitterAccount: 'twitterUsername'
}
@NgModule({
  imports: [
    // the module you choice 'ShareModule', 'ShareButtonModule' or 'ShareButtonsModule'
    ShareButtonsModule.forRoot({ options: customOptions })
  ]
})| Option | Default value | Description | 
|---|---|---|
| include | [ ] | Include certain buttons. Button's order will be as you type it. | 
| exclude | [ ] | Exclude certain buttons. | 
| size | 0 | Buttons default size. | 
| theme | null | Button theme name. | 
| dialogWidth | 500 | Share popup window width. | 
| dialogHeight | 400 | Share popup window height. | 
| url | null | Override url meta tag. | 
| title | null | Override title meta tag. | 
| description | null | Override description meta tag. | 
| image | null | Override image meta tag. | 
| tags | null | Override tags meta tag for Tumblr and Twitter. | 
| autoSetMeta | true | Initializes meta tags inputs from the SEO meta tags. | 
| gaTracking | false | Roll sharing stats automatically into your Google Analytics. | 
| twitterAccount | null | Add via @accountName at the end of the tweets. | 
When autoSetMeta is true, the meta tags inputs url, title, description and image will be initialized from the SEO meta tags.
<head>
  <meta property="og:title" content="The Rock" />
  <meta property="og:description" content="Directed by Michael Bay.  With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."/>
  <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
  <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
</head>Set
autoSetMetato false, if the share buttons url does not point to the current url, e.g. displaying a list of articles each one with share buttons.
You can change the buttons meta data such as button icon and text
import { ShareButtonsModule } from '@ngx-share/buttons';
import { faFacebookSquare, faTwitterSquare } from '@fortawesome/free-brands-svg-icons';
const customProp = {
  facebook: {
    icon: 'fab fa-facebook-official',
    text: faFacebookSquare
  },
  twitter: {
    icon: faTwitterSquare,
    text: 'Tweet'
  },
  // and so on...
};
@NgModule({
  imports: [
    ShareButtonsModule.forRoot({ prop: customProp })
  ]
})There are several classes that help you to create your custom styles
.sb-moon-theme {
  &.sb-group {
    /** ... share buttons container */
  }
  .sb-wrapper { /** ... share button wrapper */
    background-color: var(--button-color);
    .sb-inner { /** ... inner wrapper */
      .sb-content { /** ... content wrapper */
        .sb-icon { /** ... icon wrapper */ }
        .sb-text { /** ... text wrapper */ }
       }
      .sb-count { /** ... count wrapper */ }
    }
    // For conditional styles
    &.sb-show-icon.sb-show-text.sb-show-count {
      /** ... Apply when icon, text and count are shown */
      .sb-icon { /** ... icon wrapper */ }
      .sb-text { /** ... text wrapper */ }
    }
  }
}If you use .sb-moon-theme then the theme name will become moon:
<share-buttons theme="colorful"></share-buttons>❌ No Support: Means it is tested but the share dialog opens in the mobile browser
| Button | 💻 Desktop | 📱 iPhone | 📱 Android | 
|---|---|---|---|
| ✔️ Support | ❌ No Support | ❌ No Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | |
| Telegram | ✔️ Support | ✔️ Support | ✔️ Support | 
| Messenger | ❌ No Support | ✔️ Support | ✔️ Support | 
| VK | ✔️ Support | ❔ Not tested | ❔ Not tested | 
| ✔️ Support | ❌ No Support | ❔ Not tested | |
| Tumblr | ✔️ Support | ❌ No Support | ❔ Not tested | 
| StumbleUpOn | ✔️ Support | ❌ No Support | ❔ Not tested | 
| ✔️ Support | ❔ Not tested | ❔ Not tested | |
| SMS | ✔️ Support | ✔️ Support | ✔️ Support | 
| Copy | ✔️ Support | ✔️ Support | ✔️ Support | 
| ✔️ Support | ✔️ Support | ✔️ Support | |
| ✔️ Support | ✔️ Support | ✔️ Support | 
Notes:
Facebook: Does not support sharing on native apps. Tumbler: Opens in native app but then the app opens the browser again!
If you identify any errors in this component, or have an idea for an improvement, please open an issue. I am excited to see what the community thinks of this project, and I would love your input!
Murhaf Sousli

