我正在構建一個小的Angular應用程序,我正在使用Google Sign-In。我只是使用Google給出的教程中的示例代碼。谷歌登錄不識別登錄Angular的回調函數
<span class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login"
data-clientid="blah"
data-redirecturi="postmessage"
data-accesstype="offline"
data-cookiepolicy="single_host_origin"
data-callback="signInCallback">
</span>
這使得按鈕登錄的元素,並運行此代碼開始
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js?onload=start';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
,所有這一切都是由谷歌複製。然後,我有這個方法在我的控制器,
.controller('splashController', ['$scope', '$window', function($scope, $window){
$scope.googleLogin() = function(){
$scope.googleAuthResult = $window.googleAuthResult;
console.log($scope.googleAuthResult);
};
window.signInCallback = function(authResult){
console.log("happy");
};
}])
但問題是運行谷歌+腳本之後,它正在圍繞角世界之外這signInCallback功能,這是我要保持角度,因爲我想通過角度發送令牌,而不是像jQuery一樣。有什麼建議麼?
我認爲這是因爲沒有注入正確的服務或讓Angular知道$ window或其他東西,但我無法弄清楚。 –
你可以移動(函數()到控制器,或成.RUN()模塊?這可能會幫助。 –
我試圖把匿名函數到運行模式,但它不會改變,谷歌+腳本要事實在Angular中看到一個函數...雖然我更喜歡run(),因爲它更乾淨。 –