Change detection issue in ListView
See original GitHub issueConditional styling in ListView templates don’t get consistently applied. Most times they require the item to go off screen and back in, in order for the new status to be reflected.
Gif
Here is a sample to reproduce:
Component:
import {Component} from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "app.component.html",
})
export class AppComponent {
public options: string[] = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];
public selectedOption: string = "";
public onItemTap(args) {
this.selectedOption = this.options[args.index];
}
}
Markup:
<StackLayout>
<ListView #listview [items]="options" separatorColor="white" (itemTap)="onItemTap($event)">
<template let-item="item" let-i="index" let-odd="odd" let-even="even">
<GridLayout columns="44, *" height="48">
<StackLayout colSpan="2" verticalAlignment="bottom" class="line"></StackLayout>
<Label col="1" [text]="item" style="font-size:20" [class.active]="selectedOption == item"></Label>
</GridLayout>
</template>
</ListView>
</StackLayout>
CSS
.active {
color:red;
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:31 (4 by maintainers)
Top Results From Across the Web
android - How to detect change in listview from mainactivity
I noticed that it is possible to add an observer using registerDataSetObserver() that will be notified when notifyDataSetChanged() is called.
Read more >List View - NativeScript Docs
NativeScript for Angular Documentation - Using ListView. ... counts on Angular's change detection mechanism for notification that something has changed.
Read more >ListView - .NET MAUI | Microsoft Learn
ListView defines an ItemSelected event that's raised when the SelectedItem property changes, either due to the user selecting an item from the ...
Read more >List View | Mendix Documentation
With this property you can change the number of items that will be shown next to each other in one row. If you...
Read more >Help to detect any change in row selection for listview
Ok so I have used GUIEvent to detect double clicks, but row selection may change using cursor keys etc. I simply want to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This happens only on iOS, works correctly on Android.
After trying some modifications to my code, I could solve this issue by doing:
That way, when reassigning to
this.items
it’s own array, the UI got updated.