2013-11-24 43 views
1

我正在尝试在我的AngularJS网站上实现Facebook使用iframe的按钮。但Facebook按钮没有加载。Facebook喜欢在AngularJS网站中使用iframe的按钮

//html portion 
<div ng-controller="FBCtrl"> 
    <iframe ng-src="{{likeURL}}"></iframe> 
</div> 

//controller portion 
.controller('FBCtrl',['$scope', function($scope){ 
    $scope.likeURL = 'http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fflyerbd&width&layout=standard&action=like&show_faces=true&share=true&height=80'; 
}]); 

基本上我想使用Facebook像按钮,在我的网站上简单的方式。

在此先感谢。

回答

2

你应该用你的控制器$sce service,并承认为值得信赖的网址:

.controller('FBCtrl',['$scope', '$sce', function($scope, $sce){ 
    $scope.likeURL = $sce.trustAsResourceUrl('http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fwww.facebook.com%2Fflyerbd&width&layout=standard&action=like&show_faces=true&share=true&height=80'); 
} 

相关:How to set an iframe src attribute from a variable in AngularJS

+0

我用过它,但没有发生任何事。实际上应用程序崩溃了。我从我的本地主机运行它。 –

+0

@FahadBillah定义“应用程序崩溃”?产生的错误是什么?你可以发表一个例子吗? –

+1

它的我的铬的问题,我不能确定为什么这个按钮不显示铬因为没有错误报告显示在我的铬控制台(它的我的铬的问题再次)。但是你的方法确实有效。我在Firefox中运行我的网站,一切都很好。像按钮显示它假设的位置。非常感谢。 –