无法从承诺中查看数据

时间:2017-01-05 10:21:13

标签: angularjs google-calendar-api

我在angularjs中使用google calendar api并试图访问promise中的数据,但我发现数据无法访问,您可以查看并告诉我哪里出错了。

<!DOCTYPE html>
<html>
<head>
	<title>Google Cal Test</title>
</head>
<body>
	<div ng-app="MyApp" ng-controller="MyCtrl">
		Hello<span ng-bind="responsevalue"></span>
	</div>

	
	<script src="https://apis.google.com/js/client.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
	
	<script>
		angular.module('MyApp',[])
			.factory('gapi',function($window){
				return $window.gapi;
			})
			.controller('MyCtrl',['$scope','gapi','$q',myCtrl])
		
		function myCtrl($scope,gapi,$q){
			var vm = this;
			 
			var CLIENT_ID = 'CLIENT_ID HERE PLZ';
			var SCOPES = ["https://www.googleapis.com/auth/calendar"]
			console.log(gapi);
			data  = {
					'client_id': CLIENT_ID,
					'scope': SCOPES.join(' '),
					'immediate': false
				  };
			gapi.auth.authorize(data)
			.then(function(authResult){
				console.log(authResult);
				if(authResult && !authResult.error) return gapi.client.load('calendar', 'v3')
			})
			.then(function(){
				return gapi.client.calendar.calendarList.list()
			})
			.then(function(resp){
				console.log(resp);
				
				$scope.responsevalue = resp;
				console.log($scope.responsevalue);
			})
			
			
			
		}
	</script>
</body>
<html>

如果我做错了请告诉我,或者如果代码可以更好地改进,也请告诉我。

0 个答案:

没有答案