高级问题:
部分解决方案:
Specify a callback method to the onload parameter.
po.src =' https://apis.google.com/js/client:plusone.js?onload=signinCallback';
并发症:
具体问题:
https://apis.google.com/js/client.js
的异步JavaScript提取是在AngularJS的run方法中发生的。- >模块初始化:
.run([function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/client.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
}]);
虽然Google建议您异步提取https://apis.google.com/js/client.js
,但我并不坚持。但我想将大部分Google+集成代码保留在AngularJS Provider或AngularJS服务中。
任何帮助都将不胜感激。
答案 0 :(得分:0)
我没有看到使用onload方法有什么问题。
.run(['$rootScope', function($rootScope) {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/client.js';
po.onload = function(){
//it's loaded. Inject a service in your run and you can do stuff here
$rootScope.$apply(); //assuming your callback needs to do something within angular
};
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
}]);