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
*ngIf not working in Angular application for hide/show layout after upgrade to NS3 #872
I'm having some similiar issues with *ngIf, sometimes the elements are rendered out of order, sometimes aren't even rendered. Seems to be related with the last version (3.1.0).
Reacted by Paul Kim, Eddy Verbruggen, Osei Fortune, Tempura, siulikadrian, Divya Chandana, Cédric Salaün, smrasheed14, gkit1980 and Poonam Chaurasia
I have found visibility to be more stable generally. Perhaps a directive should be added here out of the box to make visibility more like ngIf in that sense - maybe even call it ngShow which would use the visibility attribute under the hood?
Reacted by Osei Fortune, jackweb, Vazy and Ryan Yu
I also have a similar issue, where after a http request and setting a boolean to true to show content, the content doesnt show. But what prompted me top try this, was the http request returns a string which is supposed to change a labels text but it didnt change. That is why I wrapped it in a ngIf but then it doesnt show at all.
After I did the upgrade and had to redo my Angular layout logic I've found these issues with ngIf:
ngIf works as expected if value is available at time of rendering
ngIf break any layout (out of order rendering of ngIf elements) if value was delayed (eg: async call)
visibility seem to be good alternative
Overall it was unpleasant to find out that what used to work with {N}2.5 is not working in {N}3.x.
At least I know, that am not alone) For anyone wondering about workarounds use [visibility] for Angular html layouts.
Reacted by MargaretaKusan, Sam Blowes, EmileXVIII and Nilesh Sutar
hey @NickIliev that was really helpful im really struggling with this issue for days.
after updating tns-core-modules ng-if working perfectly in ios. Thanks a lot for help. npm i tns-core-modules@next --save
I feel like this needs to be re-opened again, how it possible that I'm still seeing this issue in {N} 4.1.1 with tns-core-modules@next (^4.2.0-2018-07-21-02). Same with ngSwitch and [visibility] also does not work as expected. I have yet to find a workaround
The top section does now show the progress bar when u start the "upload", meanwhile the bottom section does.
The only difference between these 2 ListViews is that in the top case I pass the countries reference via [items]="countries" whereas on the bottom I pass a copy of the array each time via [items]="countries.slice()". The latter fixes the issue but this is not a solution for me because in my case the items are actually images and passing a new reference on every read causes the images to reload and jitter every digest cycle.
I have tried the same implementation with a GridView (instead of ListView) so it seems evident that the problem really arises when using *ngIf or *ngSwitch inside an *ngFor that is iterating over an array reference.
Can somebody please take a look into fixing this. Since passing an array reference is actually the correct way to use ngFor, it seems that this is a very common and rudimentary use case and it's a real bummer to have this present after 1 year of this issue being open. I currently have no workaround for this, as I would just be trading one bug for another (I have to choose between a progress bar and image jitter/constant reloads).
When I bind a function to the *ngIf instead of binding an attribute, it works fine, except for the "Expression has changed after last checked" error.
Thanks @kamok this solution worked for me. This seems to be the simplest temporary workaround that I have seen in the thread. The update to the tns core modules didn't work for me as well.
I face the same issue, but found another work around (works for me, but no guarantees...).
I place a Label above the element with the *ngIf : <Label [visibility]="mLoaded && !hasM ? 'hidden' : 'hidden'" text=""></Label> and now it works. Why?!, I don't know. I cannot explain it.
I was very excited to learn Ionic, sadly landed on Ionic 4 which seems overly unstable right now! For me, [(ngModel)] two-way binding, *ngIf, and *ngFor all not working when I do and Android release of my app... ! I can only imagine I would face the same issues on iOS... I could perhaps resolve the ngIf with that visibility workaround but how do I fix the ngFor and [(ngModel)]? I posted my model binding issues here and here if anyone could kindly offer me some help?
I have also problem with ngIf inside a p-splitter template. If I move the splitter, the ngIf seams to be ignored and all the code will be placed in the dom.
qualcentric-web-solutions commented on Oct 14, 2021
Activity
mcrvaz commentedon Jun 30, 2017
I'm having some similiar issues with *ngIf, sometimes the elements are rendered out of order, sometimes aren't even rendered. Seems to be related with the last version (3.1.0).
danielgek commentedon Jun 30, 2017
Me to, not only with *ngIf but *ngFor too
NathanWalker commentedon Jun 30, 2017
I have found
visibilityto be more stable generally. Perhaps a directive should be added here out of the box to makevisibilitymore like ngIf in that sense - maybe even call itngShowwhich would use the visibility attribute under the hood?berchik commentedon Jul 2, 2017
Same here.
u14040426 commentedon Jul 3, 2017
I also have a similar issue, where after a http request and setting a boolean to true to show content, the content doesnt show. But what prompted me top try this, was the http request returns a string which is supposed to change a labels text but it didnt change. That is why I wrapped it in a ngIf but then it doesnt show at all.
memphisvl commentedon Jul 3, 2017
After I did the upgrade and had to redo my Angular layout logic I've found these issues with ngIf:
Overall it was unpleasant to find out that what used to work with {N}2.5 is not working in {N}3.x.
At least I know, that am not alone) For anyone wondering about workarounds use [visibility] for Angular html layouts.
EddyVerbruggen commentedon Jul 4, 2017
A possible workaround for out-of-order rendering could be separating the elements in different
<StackLayout>s. My case was this:Because of the
ngFor"g2" was rendered before "g1".This fixed it:
pauly815 commentedon Jul 4, 2017
@EddyVerbruggen Your workaround resolved my issue with multiple *ngIf items better than the visibility workaround. Thanks!
sis0k0 commentedon Jul 5, 2017
Hey, guys! Can you share some code snippets where items are rendered out of order?
EddyVerbruggen commentedon Jul 5, 2017
Hi @sis0k0, here's one I hope you find useful:
fix(renderer): attach `CommentNode`s to visual tree
fix(renderer): attach `CommentNode`s to visual tree
19 remaining items
bettsjj commentedon Apr 29, 2018
NickIliev got it right. I had the problem with the following html on android only and broken on IOS. however after upgrading it works.
Thanks for your assistance
<StackLayout class="text-left" *tabItem="{title: 'Details'}">
<div *ngIf="!isLoadingImages">
<GridLayout height="250" [carousel]="gallery" carouselLabelOverlay="true" carouselSpeed="2000">
<div *ngIf="isLoadingImages">
divyachandana commentedon Jul 7, 2018
hey @NickIliev that was really helpful im really struggling with this issue for days.
after updating tns-core-modules ng-if working perfectly in ios. Thanks a lot for help.
npm i tns-core-modules@next --saveparliament718 commentedon Jul 23, 2018
I feel like this needs to be re-opened again, how it possible that I'm still seeing this issue in {N} 4.1.1 with tns-core-modules@next (^4.2.0-2018-07-21-02). Same with ngSwitch and [visibility] also does not work as expected. I have yet to find a workaround
Neither version works to show the progress bar when location.progress is updated. I can see location.progress updating in the UI via a simple
<Label>parliament718 commentedon Jul 24, 2018
Here's a playground to demonstrate the issue which is still present in {N} 4.1
https://play.nativescript.org/?template=play-ng&id=xRtLDX&v=4
The top section does now show the progress bar when u start the "upload", meanwhile the bottom section does.
The only difference between these 2 ListViews is that in the top case I pass the countries reference via
[items]="countries"whereas on the bottom I pass a copy of the array each time via[items]="countries.slice()". The latter fixes the issue but this is not a solution for me because in my case the items are actually images and passing a new reference on every read causes the images to reload and jitter every digest cycle.I have tried the same implementation with a GridView (instead of ListView) so it seems evident that the problem really arises when using *ngIf or *ngSwitch inside an *ngFor that is iterating over an array reference.
Can somebody please take a look into fixing this. Since passing an array reference is actually the correct way to use ngFor, it seems that this is a very common and rudimentary use case and it's a real bummer to have this present after 1 year of this issue being open. I currently have no workaround for this, as I would just be trading one bug for another (I have to choose between a progress bar and image jitter/constant reloads).
racknoris commentedon Aug 27, 2018
Still in NS 4+, I found that using
this.ngZone.run(() => { this.foo = false; })works well in re-rendering the view content in case it doesn't workkamok commentedon Sep 5, 2018
When I bind a function to the *ngIf instead of binding an attribute, it works fine, except for the "Expression has changed after last checked" error.
boldham31 commentedon Sep 20, 2018
Thanks @kamok this solution worked for me. This seems to be the simplest temporary workaround that I have seen in the thread. The update to the tns core modules didn't work for me as well.
WouterVanVegchel commentedon Dec 18, 2018
I face the same issue, but found another work around (works for me, but no guarantees...).
I place a
Labelabove the element with the*ngIf:<Label [visibility]="mLoaded && !hasM ? 'hidden' : 'hidden'" text=""></Label>and now it works. Why?!, I don't know. I cannot explain it.Morgs007 commentedon Jan 5, 2019
I was very excited to learn Ionic, sadly landed on Ionic 4 which seems overly unstable right now! For me,
[(ngModel)]two-way binding,*ngIf, and*ngForall not working when I do and Android release of my app... ! I can only imagine I would face the same issues on iOS... I could perhaps resolve thengIfwith that visibility workaround but how do I fix thengForand [(ngModel)]? I posted my model binding issues here and here if anyone could kindly offer me some help?jimb77 commentedon Dec 2, 2019
Any updates on this issue?
csimpi commentedon Mar 21, 2020
For me, this is still an issue. Can't really use
*ngIfproperly in NS+AngularNurtylek commentedon Jun 5, 2020
also having trouble with *ngIf, its rendering my element outside of parent element
gbro3n commentedon Mar 8, 2021
For me this wasn't working because I'd missed the inclusion of some declarations under @NgModule in app.module.ts:
stan1025 commentedon Mar 14, 2021
I have also problem with ngIf inside a p-splitter template. If I move the splitter, the ngIf seams to be ignored and all the code will be placed in the dom.
qualcentric-web-solutions commentedon Oct 14, 2021
yes i have same issue in ios app only so i added ngZone this one solved my problem for ios app.