Facebook SDK和AngularJS手动引导
我需要在Angular之前加载FB sdk,这样对sdk的任何调用都可以工作。 我试着在FB init代码中手动引导,但它不起作用 我没有错误消息,但似乎引导没有发生:Facebook SDK和AngularJS手动引导,facebook,angularjs,Facebook,Angularjs,我需要在Angular之前加载FB sdk,这样对sdk的任何调用都可以工作。 我试着在FB init代码中手动引导,但它不起作用 我没有错误消息,但似乎引导没有发生: var myApp = angular.module('myApp', ['ngRoute', 'database', ..........]) .config(function($routeProvider) { ....... }) .run(['$rootScope', func
var myApp = angular.module('myApp', ['ngRoute', 'database', ..........])
.config(function($routeProvider) {
.......
})
.run(['$rootScope', function($scope) {
//Facebook load
window.fbAsyncInit = function() {
// init the FB JS SDK
Parse.FacebookUtils.init({
appId : 'XXXXXXXXXXXXX',
//status : true,
cookie : true,
xfbml : true
});
angular.bootstrap(document.getElementById("loadAngular"), ['myApp']); // Manual Bootstrap
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}]);
关于html,我有:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body id="loadAngular">
<div id="fb-root"></div>
<div ng-controller="logController">
.....
.....
如果您有引导未发生的线索,请告诉。同一个指令可用于检查以下url: 或 试试这个
var myApp = angular.module('myApp', [...]);
myApp.config(...);
myApp.run(...);
//Facebook load
window.fbAsyncInit = function() {
// init the FB JS SDK
Parse.FacebookUtils.init({
appId : 'XXXXXXXXXXXXX',
//status : true,
cookie : true,
xfbml : true
});
angular.bootstrap(document, ['myApp']);
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
你不能在run函数内部引导应用程序,这是另一种方式-引导触发run函数,因此你必须将FB加载脚本完全移出
angular。module
Part这应该很有帮助: