Skip to content

ActionItem with *ngIf throws an error when it's removed #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tsonevn opened this issue Aug 14, 2017 · 4 comments
Closed

ActionItem with *ngIf throws an error when it's removed #942

tsonevn opened this issue Aug 14, 2017 · 4 comments
Labels

Comments

@tsonevn
Copy link
Contributor

tsonevn commented Aug 14, 2017

From @madakk on August 13, 2017 10:54

Looks like this is happening because ActionItems.removeItems calls _removeView directly: https://github.com/NativeScript/NativeScript/blob/12020bd8bbdb8d87f9100d713590d0db982b7661/tns-core-modules/ui/action-bar/action-bar-common.ts#L190

But the nativescript angular handler has already removed the view (due to the same *ngIf directive) causing the error.

I believe this can be fixed by simply checking that the item's parent is actually the actionBar before attempting to remove it.

Copied from original issue: NativeScript/NativeScript#4691

@NickIliev
Copy link

@madakk I have created this test application where an ActionItem is removed/added using *ngIf structural directive. It works as expected on both iOS and Android.

In order to investigate your specific case please provid3e more information and sample code base that can reproduce the issue you are struggling with.

@madakk
Copy link

madakk commented Aug 14, 2017

I'm sorry, I failed to notice this in my original report, this only happens when the ActionItem is provided inside an ActionBarExtension. It does appear to work properly with an ActionBar instance, as you've demonstrated.

Simply change the ActionBar to an ActionBarExtension in your testcase, and you should be able to reproduce.

Edit: Further investigation shows that the difference is that ActionBar preempts the view removal with its meta, calling removeItem instead, whereas ActionBarExtension handles the removal after it's already been removed from view, in its onActionDestroy handler.

@m-abs
Copy link
Contributor

m-abs commented Aug 24, 2017

I think I just ran into the same issue without ActionBarExtension.
I was running the iOS9 simulator.
I don't see the problem on the iOS 10.3+ simulator.

I don't have a demo project to reproduce it, but our template looks like this:

<ActionBar>
   <ActionItem
     *ngIf="(tabs.activeComponent | async) == 'bookshelf'"
     (tap)="toSettings()"
     icon="res://settings"
     ios.position="right"
     [text]="'SETTINGS' | translate"></ActionItem>     
</ActionBar>

@sis0k0
Copy link
Contributor

sis0k0 commented Sep 4, 2017

I'm closing this in favor of #978. @m-abs, I think that's another problem because it's related to the ActionBar and is iOS specific. Can you please open another issue with that sample, error log and any other information related to it?

@sis0k0 sis0k0 closed this as completed Sep 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants