Epotignano / ng2-social-share

Angular2 social share module, share urls and content on social networks such as facebook, google+, twitter, pinterest and so on -
20 stars 24 forks source link

Cannot bind to linkedIn #5

Open ivarreukers opened 7 years ago

ivarreukers commented 7 years ago

Hi, cool module. Just having 1 small problem, twitter, google+ and facebook are working perfectly. But just LinkedIn doesn't seem to work.

Code (copied from README.md):

            <button ceiboShare [googlePlus]="{url: ''}">Google+</button>
            <button ceiboShare  [facebook]="{u: ''}">Facebook</button>
            <button ceiboShare [twitter]="{url: '', text: event.title, hashtags: ''}">Twitter</button>
            <button ceiboShare  [linkedIn]="{url:''}">Linkedin</button>

Error message from Chrome:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'linkedIn' since it isn't a known property of 'button'. ("ter]="{url: '', text: event.title, hashtags: ''}">Twitter</button>
            <button ceiboShare  [ERROR ->][linkedIn]="{url:'repoUrl'}">Linkedin</button>
jbennett13 commented 7 years ago

I am having the same issue - any suggestions or insight you can offer?

jonpopp commented 7 years ago

Same here.

ivarreukers commented 7 years ago

I don't think the creator is updating the current repo, whatsapp, email, telegram and tumblr are all very easy to achieve but yet still on the roadmap. Shame, it would make a great library.

Workaround is to create LinkedIn share popup for yourself. In Angular 2, use

shareOnLinkedIn() {
    // returns the url curently in the browser
    let currentUrl = window.location.href;
    // makes the url and titles URI safe
    let encodedUrl = encodeURIComponent(currentUrl);
    let encodedTitle = encodeURIComponent("MyTitle");
    let encodedSource = encodeURIComponent("SomeDomainSource");

    this.linkedInShareUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${encodedUrl}&title=${encodedTitle}&source=${encodedSource}`;

    // In some versions the popup won't open unless it's being used to initialize a variable.
    let popup = window.open(this.linkedInShareUrl, "myWindow", 'width=800,height=600');
}

And just create a (click) event on the button instead of [linkedIn] to call this function.

<button class="ceiboShare" ceiboShare [innerHtml]="inInner" (click)="shareOnLinkedIn()"></button>

(my inInner refers to public inInner = "<img src='../images/socials/custom-linkedin.svg'>"; so I have a custom image)

Source: share-on-linkedin (under 'Customized URL')