angularjs 与object angular js比较

eanckbw9  于 12个月前  发布在  Angular
关注(0)|答案(1)|浏览(153)

我有一个问题与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);
}

py49o6xq

py49o6xq1#

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个URL执行此操作.

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);
    })
});

相关问题