Ion-list ngFor not showing


Swear I must be going crazy. I have a very simple array, and in my HTML

*ngFor=“let item of array”

Sometimes when I load this page the list shows, sometimes not! I’ve tried wrapping the array in 8 timeouts, I have no idea why this is happening.

ngFor’s work great in other parts of the app.

Has anyone ran into any edge cases where the DOM doesn’t update or something is quirky with Ionic when binding an ngFor to an array?

1 Like

Could you show us a little bit more of how you’re HTML/TS looks like? Little bit hard to tell what’s going on without that information :slight_smile:

It seems to be values emitted from a BehaviorSubject that don’t update.

If I put an event in ionViewWillEnter, the list shows just fine. There must be a bug or issue with zones or updating rxjs emitted values?

The code is as simple as displayed above.

In a service i call .next(array) on a behaviorsubject

and in the ionic page, I’m listening to the subcription. I even console log the emitted array to the console…but the DOM doesn’t show it, wild.

I’m not in the guessing game unfortunately, it would be easier if you would just show what you’re doing where then describing it :wink: . Where are you starting your subscription now in the view? Is the array already initialized/assigned etc?

Yes - sorry this is a corp project for a client where I can’t really post source.

I have decided to use Ionic Events, publishing and subscribing to those events seems to work, but listening for a BehaviorSubject .next() does not. The weirdest thing, the array is in memory and can be logged to the console, but doesn’t render in the DOM.

Anyway - sorry for the lack of clarity :frowning:

This isn’t a particularly useful thread due to the lack of code, but I suggest anybody who does happen to come across it not to be content with emulating what OP did. BehaviorSubjects do work properly, and are IMHO objectively superior to Ionic’s Events.

Indeed I’m crazy - ended up being a timing issue, both a behaviorsubject or event work as expected. False alarm.