0

I have a JSON as given below and wanted to access city element in my angularjs. I am trying record1.vendorInfo.addresses.city but it is not working here record1 is JSON data returned from $http.get.

{  
  "vendorId":"9818111362",
  "vendorInfo":{  
    "addresses":[  
      {  
        "id":1,
        "city":"Delhi",
        "locality":"Mayur Vihar Phase 1",
        "latitude":1123.4,
        "longitude":2234.5,
        "detailAddress":"Flat No. 199, gali no 6, pandav nagar",
        "addressType":"HOME"
      }
    ]
  }
}
3
  • Why do you write in bold ? we are not blind. And show the js code when it fails. Commented Jan 3, 2016 at 9:47
  • Could you show us where do you call this variable ? Commented Jan 3, 2016 at 9:49
  • I am not blind and I did nothing special to make it bold . Commented Jan 3, 2016 at 10:06

2 Answers 2

3

addresses is an Array,you should access city by rec.vernderinfo.addresses[0].city

Sign up to request clarification or add additional context in comments.

Comments

1

You have to create object from JSON. E.g. var rec = angular.fromJson(record1). Then it would be possible to navigate through properties: rec.vendorInfo.addresses.city.

1 Comment

Here is how my code looks like:. Please suggest . RecordApp.factory('recordaccess', ['$http', function($http) { return $http.get('record1.json') .then(function successCallback(response) { return response.data; }, function errorCallback(response) { alert("Error occurred. Status: " + response.status + " - " + response.statusText); }); }]); RecordApp.controller('MyController', ['$scope', 'recordaccess', function($scope, recordaccess) { recordaccess.then(function(data) { $scope.record1 = data; }); }]);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.