0

I am facing a issue where I want to display the all keys in a table cell but the keys which are already in my db will be displayed with different background color; I tried with ng-repeat twice but it does not get succeed as it repeat the existing keys ;

here is the plunker to get more understanding

and here is the relevant code

 d.keys = ['a','b'] // from database
 keys = ['a','b','c','d'] // complete list

 <span ng-repeat="vk in keys">
    <span ng-repeat="dk in d.keys">
       <span ng-show="vk === dk" class="key  {{ dk }}">{{ dk }}</span>
       </span>
       <span class="key">{{ vk }}</span>
     </span>
  </span>

Please suggest any better solution if possible; I read some filter method but didn't get the idea

1 Answer 1

2

you really just want to modify the class for the span I believe. Just one ng-repeat and then set the class with ng-class

<span ng-repeat="vk in keys">
   <span class="key" ng-class="d.keys.indexOf(vk) >= 0 ? vk : ''">{{ vk }} </span>
</span>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. Actually I need to lowercase the class name so I write ? '{{vk | lowercase}}' and it's works like magic

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.