如何在$ http.get状态下指定函数名称?

时间:2015-08-31 02:15:33

标签: angularjs

我有一个看起来像这样的角度函数。

function request($scope, $http) {    
  $http.get("http://www.w3schools.com/angular/customers.php")
  .success(function (response) {
     $scope.names = response.records;
  });
}

我喜欢用常规函数替换匿名函数只是为了摆脱丑陋的缩进。我不确定我在做什么,因为我没有太大的成功。基本上,我喜欢看起来像这样。

function request($scope, $http) {

  processGoodStatus = function (response) {
     $scope.names = response.records;
  }

  $http.get("http://www.w3schools.com/angular/customers.php")
  .success(processGoodStatus);
}

怎么会这样呢?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

您忘记使用var

像这样声明

var processGoodStatus = function (response) {
     $scope.names = response.records;
}