我的 HTML 中有这个
<div class="container" ng-controller="MyControl">
....(some html removed)....
<fb-like data-href="...." data-send="false" data-layout="button_count" data-width="120" data-show-faces="false" data-font="verdana"></fb-like>
在我的 JS 中,我没有将 Facebook 异步初始化放在 MyControl 中,而是放在其他一些控件中。并在文档准备好时加载 Facebook 脚本。
function SomeOtherControl($scope,$rootScope) {
...(some code removed)....
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '...', // App ID from the App Dashboard
channelUrl : '...', // Channel File for x-domain communication
status : false, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
FbLogin($scope,true);
$rootScope.lastFbLogin = new Date();
$rootScope.$apply('lastFbLogin')
};
angular.element(document).ready(function(){
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
})
lastFbLogin 现在是空的
$rootScope.$watch('lastFbLogin',function(newVal,oldVal){
if (!!newVal) {
}
});