Get the JSON result from the popup. Angular.JS

I got a popup that calls a RESTful server for Oauth authentication, but when the result returns, it displays JSON in the popup, rather than closing the popup and saving the JSON in the model, How to fix it?

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); }; 
+6
source share
1 answer

The described situation is probably not the best way to solve your problem in Angular. I assume this is written inside the controller. If so, the backend service call is best done using the $http service. For this

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)); }); } }]) 
0
source

Source: https://habr.com/ru/post/985975/


All Articles