1

I want to display data in ul / li so I am fetching it through loop in my html like :

I have two array where :

  $mainarray = [{"Name":"data1","count":9},{"Name":"data2","count":10},
 {"Name":"data3","count":4},{"Name":"4","count":20}];


 $color = ['red','pink','green','yellow','black'];
 $color = ['red','pink','green','yellow','black'];

I am looping through main array like this and its working fine :

<ul style="list-style-type:circle; padding: 0px !important; font-size:22px;">
<li ng-repeat="item in mainarray " style="margin-bottom: 10px;"; >
    <span style=" font-size: 16px; ">{{ item.name }}</span>
</li>
</ul>

However, I want to add $color with this like :

for data1 -> red
data2->pink 
and so on ....

I have tried with multiple loop but its not working !

Any clues ?

1

1 Answer 1

1

Your can use $index

<span style=" font-size: 16px; ">{{ item.name }} -> {{ color[$index] }}</span>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks , but how to place this color in style ? As when i use style = "color={{color[$index]}}, its not working"
@CodeWithCoffee You can try ng-style stackoverflow.com/questions/21364445/…
This answer from above link stackoverflow.com/a/26301609/1984039 does it with plain style.
Thanks @gurvinder

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.