$ http({method:'GET',url:$ scope.url})中的回调

时间:2013-10-21 17:54:08

标签: http angularjs get

$scope.fetchQA = function() {

    $scope.url = 'js/jsons/QA.json';

    $http({method: 'GET', url: $scope.url}).
      success(function(data, status, headers, config) {
        $scope.QA = data;
    });
  }

  $scope.fetchQA();

  function x(){
    alert(QA);
  }

如何使用function x作为$ http.get的回调?还是有其他方法可以确保只有在fetchQA收到数据后才会执行x()?

1 个答案:

答案 0 :(得分:2)

在你的逻辑之后把它放在回调中:

$http({method: 'GET', url: $scope.url}).
  success(function(data, status, headers, config) {
    $scope.QA = data;
    x();
});