Error: View not added to this instance


#1

This error is returned when dealing with ng-template else syntax:

JS: ERROR Error: View not added to this instance. View: TextNode(9) CurrentParent: undefined ExpectedParent: Page(7)
JS: ERROR CONTEXT [object Object]

This is the view:

<Page xmlns="http://schemas.nativescript.org/tns.xsd">
    <GridLayout rows="80, *, 80" *ngIf="user; else loading">
        ...
    </GridLayout>
    <ng-template #loading>
        <StackLayout verticalAlignment="center" height="100%">
            <Label text="loading"></Label>
        </StackLayout>
    </ng-template>
</Page>

For some reason this only happens when you close and reopen the app, being this component remembered as the root one. The template block works fine when you come from a login component as the root into this one.
Also the conditional works fine if I remove the else block so the problem isn’t the user property.

And the last clue… If I remove ng-template and just use a falsey value as a conditional for the loading block, it also works:

<StackLayout verticalAlignment="center" height="100%" *ngIf="!user">
     <Label text="loading"></Label>
</StackLayout>

So there seems to be something wrong with the else implementation…

Any ideas? Thanks!


#2

Did you fix this? I am running into the same issue.