0

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>

3 Answers 3

1

try this

{{f.doctorName}} 

instead of "doctorName"

Check my plunker

0

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.)

0
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.