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!

1
  • 1
    Just use | filter:{value:'!! '} Commented Sep 4, 2017 at 13:27

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you that worked! I was over thinking it by creating a filter in the module.
Please accept the answer as it will be useful for other visitors.
Will do, it has a time limit tho :)
sure thanks. Let know if you have any other difficulties
You marked it duplicate after i gave the answer.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.