我有一个弹出窗口调用 RESTful 后端来进行 Oauth 身份验证,但是当返回结果时,它会在弹出窗口中显示 JSON,而不是关闭弹出窗口并将 JSON 存储在模型中.我该如何解决这个问题?
this.socialLogin = function(provider) {
var url = urlBase + '/' + provider,
width = 1000,
height = 650,
top = (window.outerHeight - height) / 2,
left = (window.outerWidth - width) / 2,
socialPopup = null;
$window.open(url, 'Social Login', 'width=' + width + ',height=' + height + ',scrollbars=0,top=' + top + ',left=' + left);
};
最佳答案
所描述的情况可能不是解决 Angular 问题的最佳方法。我假设这是在 Controller 内部编写的。如果是这样,调用后端服务最好使用 $http
服务。为此,
Controller .js
angular.module('example')
.controller(['$scope', '$http', '$window', function($scope, $http, $window) {
$scope.socialLogin = function(urlEnd) {
$http.get(urlBase + '/' + urlEnd) // Should probably be posting here...
.then(function(res) { // Your JSON response here
$scope.doSomethingWithTheResponse(res.data);
}, function(err) { // Handle your error
$window.alert("We got us an error!\n" + JSON.stringify(err));
});
}
}])
关于javascript - 从弹出窗口获取 JSON 结果。 Angular .JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29872387/