1

I have an Angular array that contains JSON data. One of the elements is the name of an ionic icon. I am using ng-repeat to loop through the elements and I want to dynamically update the ionic icon name on each iteration.

<div class = "row" ng-repeat="item in serviceList" ng-switch   on="$index % 3">
  <div class = "col text-center" ng-switch-when="0">
      <i class = "services icon ion-laptop">{{ serviceList[$index].IconName }} </i>
  </div>

  <div class = "col text-center" ng-switch-when="0"> 
    <i class = "services icon ion-laptop">{{ serviceList[$index+1].IconName }}</i>
  </div>

In this example I have manually set ion-laptop, but I want to use serviceList[$index].IconName and serviceList[$index+1].IconName }} respectively to update the icon. The above code will output the icon name string, but I cannot figure out how to place that inside of the HTML class tag. Any thoughts?

1 Answer 1

0
<div class = "row" ng-repeat="item in serviceList" ng-switch   on="$index % 3">
  <div class = "col text-center" ng-switch-when="0">
      <i class = "services icon {{ serviceList[$index].IconName }}"> </i>
  </div>

  <div class = "col text-center" ng-switch-when="0"> 
    <i class = "services icon {{ serviceList[$index+1].IconName }}"></i>
  </div>

No big issue.. GO Ahead

Sign up to request clarification or add additional context in comments.

1 Comment

ng-class instead of class

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.