0

Now I have a list of Items. Items are retried from API. Now I need to highlight Selected Item. when the page loads the first item is selected and then I select another item so highlight this item and the first item's highlight removed.

In this Img I selected the second item and add a border as shows it selected by the user.

Ex Img

<!--I share Code-->
   <ion-list *ngFor="let item of items">
      <ion-item >
          {{item.name}}
       </ion-item>
     </ion-list>

1 Answer 1

1

You could use ngClass for this.

<ion-list *ngFor="let item of items" (click)="selectItem(item)">
    <ion-item [ngClass]="{'item-selected':item.value === yourSelectedModelValue}">
        {{item.name}}
    </ion-item>
 </ion-list>

And inside your class.

selectItem (item) {
    this.yourSelectedModelValue = item;
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks ! item.value = name & what about yourSelectedModelValue.
@Pritesh yourSelectedModelValue thats the value for which the selection to be done
I have sub item so how can i highlight that
@Pritesh same logic. Use ngClass with another scope variable.

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.