user2726041
user2726041

Reputation: 359

How do I get a single value from a json file using angular (without using ng-repeat)?

I have a json file with the following data:

{
  "favicons": [
    {
      "36x36”: "36x36.png",
      "48x48": "48x48.png",
      "57x57": "57x57.png"
    }
  ],
  "header": [
    {
      "imageUrl": "logo.png",
      "subTitle": “blah”,
      "backgroundColor": "#c30909"
    }
  ]
}

I'd like to retrieve the value of favicons.36x36 without using ng-repeat.

I have this in my app.controller:

app.controller('myCtrl', function($scope, $http) {  
    $http.get("data.json").then(function (response) {
      $scope.faviconData = response.data.favicons;
    })
});

Using {{faviconData}} in my HTML, I can output the entire array.

But {{faviconData.36x36}} results in a parse syntax error.

I have also tried faviconData[0].36x36 but this also results in an error.

Upvotes: 0

Views: 582

Answers (1)

Matuszew
Matuszew

Reputation: 851

Do this

{{faviconData[0]['36x36']}}

Upvotes: 3

Related Questions