single page application with angularjs and facebook share button

前端 未结 2 881
心在旅途
心在旅途 2020-12-12 18:20

I follow this post to deploy facebook share botton in my app http://www.hyperarts.com/blog/tutorial-how-to-add-facebook-share-button-to-your-web-site-pages/

The firs

2条回答
  •  爱一瞬间的悲伤
    2020-12-12 19:19

    Here's also a directive built based on Chickenrice's answer.

    Html:

    
      

    Directive:

    'use strict';
    /* global FB */
    
    myApp.directive('fbShare', [
        function() {
            return {
                restrict: 'A',
                link: function(scope, element) {
                    element.on('click', function() {
                        FB.ui({
                            method: 'feed',
                            name: 'Name you want to show',
                            link: 'http://link-you-want-to-show',
                            picture: 'http://picture-you-want-to-show',
                            caption: 'Caption you want to show',
                            description: 'Description you want to show',
                            message: 'Message you want to show'
                        });
                    });
                }
            };
        }
    ]);
    

    If you use jshint (you should) the /* global FB */ part is there in so you don't get undefined variable warning.

提交回复
热议问题