Nativescript-angular: Conditionally displaying a tab in tabview with *ngIf

Created on 6 Jan 2017  路  2Comments  路  Source: NativeScript/nativescript-angular

I'm getting an exception when using *ngIf to show/hide tab;

    <TabView>

        <!-- TAB1 -->
        <template tabItem title="TAB1">
                      <Label text="Toggle" (tap)="showTab2 = !showTab2" ></Label>
        </template>

        <!-- TAB2 -->
        <template tabItem title="TAB2" *ngIf="showTab2">
            <Label text="Tab2" textWrap="true"></Label>         
        </template>

    </TabView>

caused by: View not added to this instance. View: Label(1753) CurrentParent: undefined ExpectedParent: TabView(793)
1   0x10e660f9b NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
2   0x10ede365e ffi_closure_unix64_inner
3   0x10ede4012 ffi_closure_unix64
4   0x10fdd619a _UIGestureRecognizerSendActions
5   0x10fdd4197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
6   0x10fddc655 ___UIGestureRecognizerUpdate_block_invoke898
7   0x10fddc4f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks
8   0x10fdc9e75 _UIGestureRecognizerUpdate
9   0x10f95648e -[UIWindow _sendGesturesForEvent:]
10  0x10f9576c4 -[UIWindow sendEvent:]
11  0x10f902dc6 -[UIApplication sendEvent:]
12  0x10f8dc553 _UIApplicationHandleEventQueue
13  0x111c1f301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
14  0x111c1522c __CFRunLoopDoSources0
15  0x111c146e3 __CFRunLoopRun
16  0x111c140f8 CFRunLoopRunSpecific
17  0x1147acad2 GSEventRunModal
18  0x10f8e1f09 UIApplicationMain
19  0x10ede3e6d ffi_call_unix64
20  0x128a31560
file:///app/tns_modules/rxjs/Subscriber.js:227:22: JS ERROR Error: Error in pages/test.html:52:12 caused by: View not added to this instance. View: Label(1753) CurrentParent: undefined ExpectedParent: TabView(793)
Jan  6 13:36:47 SpringBoard[52639]: UNNotificationRegistrarConnectionListener connection invalidated
Jan  6 13:36:47 com.apple.CoreSimulator.SimDevice.-AAD3-40AD-B15F-1D1382B079AC.launchd_sim[52623] (UIKitApplication:com.ecowell.healthsignal[0xb0a][83011]): Service exited due to signal: Segmentation fault: 11
question

All 2 comments

Hey @devna13

Indeed you can not use a structural directive to remove a tab from the visual tree.

However, you can remove the tab via code behind.
As a side note, you are using the