ManelPNavarro
ManelPNavarro

Reputation: 579

ng-if condition with key value - Angular js

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.

Upvotes: 1

Views: 2528

Answers (1)

Vineet
Vineet

Reputation: 4635

Just Try

<p ng-repeat="item in items track by $index" ng-show="$index == 'sleeves'">            
   {{$index}} - {{item}}
</p>

Upvotes: 2

Related Questions