0

I'm trying to iterate through a JSON array in my view, but I want to only show the keys that has values that are non empty strings.

design:
{name: "ux", value: "3", $$hashKey: "object:5198"}
{name: "graphic", value: "", $$hashKey: "object:5199"}
{name: "concept", value: "4", $$hashKey: "object:5200"}
{name: "photoshop", value: "", $$hashKey: "object:5201"}
{name: "illustrator", value: "5", $$hashKey: "object:5202"}
{name: "inDesign", value: ""}
{name: "afterEffects", value: ""}
{name: "premierePro", value: "1"}

How would I only get the keys of the array while iterating through the array and only show the ones that have a real value.

The current code that I have is:

<div class="six columns">
                        <div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'! '}">
                            {{ skill.name | capitalize }} {{ skill.value }}
                        </div>
                    </div>

Any help would be highly appreciated!

qasimalbaqali
  • 2,079
  • 24
  • 51

1 Answers1

1

You can use ng-if in this case:

<div class="six columns">
     <div ng-repeat="skill in employeeDetails.design | limitTo:5:0" ng-if="skill.value !== '' ">
             {{ skill.name | capitalize }} {{ skill.value }}
      </div>
</div>

or change your filter

<div class="six columns">
         <div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'!! '}" ng-if="skill.value !== '' ">
                 {{ skill.name | capitalize }} {{ skill.value }}
          </div>
    </div>
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62