You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Angular 9: Using ngIf changes order of children inside a StackLayout #2176
Describe the bug
After upgrading from Angular 8 to Angular 9: When using *ngIf on a component that's together with other components wrapped by a StackLayout, the component with ngIf is always added as the last child when the Page is rendered.
Just to add in case it helps: this is occuring in FlexboxLayout as well as the StackLayout mentioned above. An *ngIf directive on either an ng-container or directly on an element causes it to always come after elements that don't have the directive, even if the initial value of the *ngIf is true
I tried manually triggering change detection using ChangeDetectorRef after all elements were loaded, with no luck.
As a work around, I have added an *ngIf with a variable that is always true to all the elements that did not already have an *ngIf. It seems to be working. The two components I have tried so far are in the correct order after doing this. I didn't really expect it to work since the other *ngIf items are mostly using observables with async. I thought since they will most likely be resolving at various times, things would still be out of order, but surprisingly enough, that doesn't seem to matter. One just needs to *ngIf all the things.
Update: I found a component where this didn't work, so it isn't a perfect work around. Still, it mostly works.
Update 2: I don't know if this brings anything to the table, but this isn't an entirely new issue. I have never been able to resolve an ordering issue with the following (don't mind the Pug, I love the cleanliness of Pug):
The carousel was supposed to display after the first item in the ngFor, but it always sat at the bottom of the list. Now, it displays in the correct position with the magic *ngIfs. The following displays in the correct order:
Activity
chevallard commentedon Jun 23, 2020
Just to add in case it helps: this is occuring in FlexboxLayout as well as the StackLayout mentioned above. An
*ngIfdirective on either an ng-container or directly on an element causes it to always come after elements that don't have the directive, even if the initial value of the*ngIfistrueI tried manually triggering change detection using ChangeDetectorRef after all elements were loaded, with no luck.
sublime392 commentedon Jun 23, 2020
As a work around, I have added an
*ngIfwith a variable that is always true to all the elements that did not already have an*ngIf. It seems to be working. The two components I have tried so far are in the correct order after doing this. I didn't really expect it to work since the other*ngIfitems are mostly using observables withasync. I thought since they will most likely be resolving at various times, things would still be out of order, but surprisingly enough, that doesn't seem to matter. One just needs to*ngIfall the things.Update: I found a component where this didn't work, so it isn't a perfect work around. Still, it mostly works.
Update 2: I don't know if this brings anything to the table, but this isn't an entirely new issue. I have never been able to resolve an ordering issue with the following (don't mind the Pug, I love the cleanliness of Pug):
The carousel was supposed to display after the first item in the
ngFor, but it always sat at the bottom of the list. Now, it displays in the correct position with the magic*ngIfs. The following displays in the correct order:Here, the newly added
showLayoutis just this variable added to the component:public showLayout = true;.crowmagnumb commentedon Jun 26, 2020
This one is biting me in so many ways now. :) Hoping there is a fix real soon for this. :)
OliverNiebsch commentedon Jul 10, 2020
Are there any news on this? Really looking forward to this since it's messing up my UI and I don't like the workaround at all :/
iamabs2001 commentedon Jul 25, 2020
in Progress...
pekevski commentedon Aug 20, 2020
I see this occur with an *ngFor
The BBB label will appear before the ngFor labels.
ivanthz commentedon Sep 16, 2020
For now I'm using an additional Stack to get around the problem:
crowmagnumb commentedon Sep 16, 2020
I have not seen this in the nativescript 7 release. I believe this has been fixed.
ivanthz commentedon Sep 18, 2020
Can you share your package.json?
I'm using NS 7 with Angular 10 and the problem still here.
crowmagnumb commentedon Sep 18, 2020
Did you follow this upgrade process? I had some issues with it but have them ironed out now.
You should have the latest nativescript globally installed ...
The relevant parts of my
package.jsonare ...