2016-08-06 2 views
0

여기 내 코드와 ng-repeat가 목록을 생성했지만 아무것도 표시하지 않습니다. ng-repeat가 아무 것도 표시하지 않습니다.

<!DOCTYPE html> 
<html lang="en"> 
<head> 


</head> 
    <body ng-app="myApp"> 

    <div ng-controller="getHospitalCtrl"> 

     <h3>my list</h3> 
      <ul> 
       <li ng-repeat="hospital in hospitals track by $index"> 
        <p class="name">{{hospital.name}}</p> 
        <p class="location">{{hospital.address.city}}</p> 
       </li>    
      </ul> 
     </div> 

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script> 
     var app = angular.module('myApp',[]); 
     app.controller('getHospitalCtrl',function($scope, $http){ 

     console.log('i m in getHospitalCtrl'); 

     $http.get("url") 
     .then(function(response){ 
      $scope.hospitals = JSON.stringify(response.data.data); 
      console.log($scope.hospitals); 
      //this console is printing the right json here 
    }); 

}); 
     </script> 

    </body> 
</html> 

콘솔의 JSON이

[{ "_id"처럼 "57a5877bb23cda352156315a", "userId를"257 "이름": "포티스", "이메일": "포티스 @ 병원 "주소": { "postalCode": "110088", "상태": "DL", "도시": "뉴 델리", "streetAddress": " S-포티스 "},"좌표 ": {"좌표 "[77.1545846,28.7164134,"유형 ":"포인트 "}}] 코드에서

+0

하여 JSON 배열을 console.log (response.data)와 동일합니다 :

당신은 단지 하나의 초기화를해야합니까? –

답변

1

봐 :

먼저

$scope.hospitals = response.data; 

$ scope.hospitals를 http 응답으로 반환되는 것으로 초기화합니다.

하지만 당신은 그래서 당신은 문자열으로이 값을 덮어 쓰기하고

$scope.hospitals = JSON.stringify($scope.hospitals.data); 

이 직후. 문자열에 ng-repeat을 사용하는 것은 의미가 없습니다. ng-repeat배열을 반복하는 데 사용됩니다.

$scope.hospitals = response.data.data; 
관련 문제