0

I have a json something like this

{
 "count": 67,
 "0": {
    "id": "2443",
    "name": "Art Gallery",
    "category": {
        "id": "2246",
        "name": "Gifts & Memories"
    },
   "deckLocation": [
      {
        "id": "2443",
        "deck": {
          "deckNo": "7",
          "deckName": "Promenade "
        },

      }
    ]
},
"1": {
  "id": "7198",
  "name": "Captain's Circle Desk",
  "category": {
    "id": "352",
    "name": "Other Services"
  },
  "deckLocation": [
    {
      "id": "7198",
      "deck": {
        "deckNo": "7",
        "deckName": "Promenade "
      },

    },
    {
      "id": "7198",
      "deck": {
        "deckNo": "7",
        "deckName": "Promenade "
      },

    }
   ]
 }
}

I want to display all names which is inside the "0", "1" array. I can able to list a specific name but not all. The fist name will display which I written in the following code. But I need to display all 0, 1, 2, 3 etc names dynamically.

data[0].name

Please help me. Thank you.

3 Answers 3

4

use ng-repeat function to do so.

<div ng-repeat = "names in data">
<P>{{names.name}}</P>
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

Let us say you have a service like this:-

    var todoApp = angular.module("todoApp",[]);

    todoApp.factory('dbService', ['$q','$http',function ($q , $http) {  
    var service ={};
        service.getUrl = function (urlToGet) {
            var svc=this;

            var deferred = $q.defer();
            var responsePromise = $http.get(urlToGet);

            responsePromise.success(function (data, status, headers, config) { 
                deferred.resolve(data);  });

            responsePromise.error(function (data, status, headers, config) { 
                deferred.reject({ error: "Ajax Failed", errorInfo: data });});

            return (deferred.promise);
        }
        return service;
        }]);

And you want to load a file named '/js/udata.json'. Here is how in you controller you can load this file:-

todoApp.controller("ToDoCtrl", ['$scope','$timeout','dbService',function($scope, $timeout, dbService)
{
    $scope.todo={};

  $timeout(function(){
   dbService.getUrl('/js/udata.json').then(function(resp){
    $scope.todo=resp;
   });},1);
};

Hope this helps!

Comments

0

You have data[0].name right?

then why don't you loop through that to get all the name elements in those arrays.

like...

for(i=1;i<data.length;i++)
{
console.log(data[i].name);
}

Comments

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.