【发布时间】:2016-09-10 02:13:31
【问题描述】:
我正在尝试在页面加载时使用 Google Cloud Endpoints 和 AngularJS 发出发布请求,以便获取用户信息并填写个人资料图片、个人资料描述等...
我可以在按下按钮或类似按钮时运行请求,但在页面加载时无法自动调用谷歌端点,这就是我想要实现的目标。
下面是应该在 Angular 脚本中加载 {{userPicture}} 的 HTML 部分:
(HTML)
<div class="form-group">
<label class="col-sm-3 control-label">Profile image</label>
<div class="col-sm-9" ng-controller='initController'>
<img src="{{userPicture}}" class="user-image-profile" alt="User Image">
</div>
</div>
(角度)
controllers.initController = function($scope, $http){
$scope.userForm = {
"userEmail" : $.cookie('auth')
};
gapi.client.igardenendpoints.getProfile($scope.userForm).execute(function(resp) {
$scope.$apply(function () {
if (resp.error) {
$scope.backmessage.messagetext = "GetProfile Error!"
console.log("error");
} else {
if (resp.userEmail == "TEMPLATE"){
$scope.backmessage.messagetext = "Error please try again!"
}else{
$scope.userPicture = 'https://filiperebollo1986.appspot.com/serve?blob-key=' + resp.profilePicKey;
}
}
});
});
}
我还尝试使用以下内容:
$scope.initData = function () {
gapi.client.igardenendpoints.getProfile($scope.userForm)............
}
并在控制器末尾运行函数,例如:
$scope.initData();
但两者都不起作用,有什么帮助吗?
【问题讨论】:
标签: angularjs google-app-engine google-cloud-endpoints