1

I'm testing a webapp using angularjs, my app.js is reading a JSON file and gets some data:

var category = document.getElementById('category').value;
var App = angular.module('App', []);

App.controller('control', function($scope, $http){
$http.get('../../zz-dashboard/motores/datatodo/INFO/filtros/'+category+'.json')
  .then(function(res){
    $scope.items = res.data;              
  });
});

I would like to show the data conditioned in the key or val value, using ng-if. For example, in this case if the key of my array is equal to "sleeves" I would like to show the value, only in that case.

<p ng-repeat="(key, val) in items" ng-if="key=='sleeves'">            
   {{key}} - {{val}}
</p>

I'm new in angularjs and I didn't found a clear answer to my question, I would apreciate any help.

0

1 Answer 1

2

Just Try

<p ng-repeat="item in items track by $index" ng-show="$index == 'sleeves'">            
   {{$index}} - {{item}}
</p>
Sign up to request clarification or add additional context in comments.

5 Comments

You can't answer like this if you haven't seen his json code... This work in certain case.
This didn't work with my json, but "ng-show" did it.
How you can get $index as sleeves (string). $index is a number right.
I assumed from OP's question. He said ng-if="key=='sleeves'". I assumed that OP must has indexing as a string.
Yes, it is indexing as a string.

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.