single page application with angularjs and facebook share button

前端 未结 2 880
心在旅途
心在旅途 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:20

    I think you could register share button click event handler in "Angular way". Move the logic to controller and use ng-click directive to trigger share action.

    My implementation

    HTML

    
      
    {{post.title}}
    {{post.content}}

    Controller

    angular.module("myApp",[])
    .controller("fbCtrl",function($scope){
      $scope.posts = [{id:1,title:"title1",content:"content1",caption:"caption1"},{id:2,title:"title2",content:"content2",caption:"caption2"}];
      $scope.share = function(post){
        FB.ui(
        {
            method: 'feed',
            name: 'This is the content of the "name" field.',
            link: 'http://www.hyperarts.com/external-xfbml/'+post.id,
            picture: 'http://www.hyperarts.com/external-xfbml/share-image.gif',
            caption: post.caption,
            description: 'This is the content of the "description" field, below the caption.',
            message: ''
        });
      }
    });
    

    Screenshot

    enter image description here

    You could create a service for FACEBOOK sharing if this function will apply to multiple parts.

    Hope this is helpful.

提交回复
热议问题