Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm new to AngularJs and i'm trying to make web with angular.js and PHP.I'm having some trouble on displaying data from a Json . My controller

 $scope.careprovider = function() {
           $http.post('php/homefunctions.php', {
                'act': 'careprovider'
            }).success(function(data, status, headers, config) {
                 if (data.sessionError == 1) {

                     $location.path("/Login");


                }else {
                    alert(data.careproviders);
                      $scope.careprovider = data.careproviders;
                       $scope.specializations = data.specializations;
                }
            }).error(function(data, status) { 
                $scope.errors.push(status);
            });
        }

I have JSON Array object as shown below

 {"careproviders":
    {"Anaesthesiologists":
    [{"id":"37","addedBy":"5463e2dc0f","doctorName":"test","email":"[email protected]","hasUpdation":"NO"},
    {"id":"38","addedBy":"62f5d33584","doctorName":"test1","email":"[email protected]","hasUpdation":"NO"}],
    "Cardiologist":
    {"id":"38","addedBy":"62f5d33584","doctorName":"test2","email":"[email protected]","hasUpdation":"NO"}]}

I want to get the keys and values separately using ng-repeat in angular.js.Here is my html

<div ng-repeat="f in careprovider">
      <div class="cus-row-head">want show here the key</div>
        <div class="row cus_row clearfix cus-sep-row posrel">
               <div class="col-xs-12 col-md-12">
                     <div class="col-xs-6 col-lg-8 cus-col-mob-4">
                        <span class="cus-md-font">want to show here the doctor name</span>
                           <span class="cus-sm-font cus-inline">
                              <span class="glyphicon glyphicon-envelope"></span> email </span>

                       </div>
                      </div>
                   <a class="icons_sm icons-sm-edit"></a> 

              </div>
         </div>
share|improve this question

3 Answers 3

up vote 0 down vote accepted

Check out this jsfiddle I put together which has the type of structure you want.

If you want to loop through the keys of an object, your ng-repat should look like this:

<div ng-repeat="key in keys(object)"></div>

Where keys is defined in your controller as:

$scope.keys = function(obj){return obj? Object.keys(obj) : [];}

(BTW, your json has a missing '[' character in it.)

share|improve this answer
    
Thank you ..its working –  Meera Sebastian Nov 13 '14 at 18:46

try this

{{f.doctorName}} 

instead of "doctorName"

Check my plunker

share|improve this answer

Try doing this:

ng-repeat="(key, value) in data"

Then you can access {{key}} and {{value}}

The method is mentioned here: https://docs.angularjs.org/api/ng/directive/ngRepeat

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.