javascript - 从弹出窗口获取 JSON 结果。 Angular .JS

标签 javascript json angularjs

我有一个弹出窗口调用 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/

相关文章:

javascript - Zepto 的 $.post 没有错误处理程序

javascript - Adobe Acrobat Pro XI - 将 Javascript 添加到 PDF

javascript - 将 s3 对象数据放入数组 - Node

javascript - AngularJS ng-repeat map (对象)不实时更新 DOM

json - JSON 序列化程序中的延迟加载错误

javascript - 如果我将名称作为属性而不是标签,为什么指令不起作用?

android - 如何更新 JSON 文件数组中的特定对象?

java - 将没有特定标准结构的 JSON 解析为 Map 或 Java 对象

javascript - 在实例化 Controller 之前未解析 JSON 对象

html - 为什么我不能将所有 4 个元素都放在同一行中?