与物体角度js相比较

时间:2016-03-07 16:49:33

标签: angularjs json api call

我有一个AngularJS的问题我从api json那里收到json包含一个prod url和url prerpod我会调用这些API来检索一个新的json然后比较结果来验证哪个是相同的问题是我有200个aPI测试我该怎么办。先感谢您 ps我认为使用该方法的测试对象等于。

我有100个像这样的对象:

{
    "ID": "1",
    "URL_preprod": "url1",
    "Preprod_bis": "url2",
    "prod": "url3",
}

我需要检查每个对象的调用结果是否相等。

  function callAtTimeout() {
   if ($scope.preprod && $scope.preprodBis) {
      angular.equals($scope.preprod,$scope.preprodBis);
      $scope.msg = "equals";
      }}



   $scope.test = function() {
 if (tnrArray) {
 for (var i = 0; i < tnrArray.length; i++) {

  var urlPreprod = tnrArray[i].URL_preprod;
    console.log(urlPreprod);
  $http.get(urlPreprod).success( function(response) {
    $scope.preprod = response;
    console.log(response);
   });

   var urlPreprodBis = tnrArray[i].Preprod_bis;
   console.log(urlPreprodBis);
   $http.get(urlPreprodBis).success( function(response) {
     $scope.preprodBis = response;
     console.log(response);
    });
     $timeout(callAtTimeout, 3000);
}

1 个答案:

答案 0 :(得分:0)

var response1;

$http.get("/your/url").then(function(response) {
    response1 = response;
    return $http.get(response.prodUrl);
}).then(function(prodResponse) {
    console.log(prodResponse);
    console.log(_.isEqual(response1 , prodResponse));  // uses lodash
}).catch(function(badResponse) {
    console.log("oops something went wrong", badResponse);
})

这应该有用 - lodash用于检查是否相等

为异步的200个网址做这个......

var urlList = ['/path/url1','/path/url2','/path/url3'];

angular.forEach(urlList, function(url) {

    var response1;

    $http.get(url).then(function(response) {
        response1 = response;
        return $http.get(response.prodUrl);
    }).then(function(prodResponse) {
        console.log(prodResponse);
        console.log(angular.equals(response1 , prodResponse));
    }).catch(function(badResponse) {
        console.log("oops something went wrong", badResponse);
    })
});