Skip to content

ngFor broken in child components with delayed initialization #2361

@OzymandiasTheGreat

Description

@OzymandiasTheGreat

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 7.2.1
  • Cross-platform modules: 7.1.4
  • Android Runtime: 8.0.0
  • iOS Runtime:
  • Plugin(s):
  • NativeScript-Angular: ~11.0.0
  • Angular: ~11.0.0

Describe the bug

Using ngFor in child components (embedded via template selector in HTML) when child component is initialized with a delay,
such as with ngIf or ngSwitch with a false initial value, is broken. The loop executes the correct number of times, but every item is either null or undefined and other loop variables are wrong too, e.g. index is -1 for every iteration.

Edit: After more testing, it seems you don't even need a child component. If ngFor array is set from a promise, ngFor breaks as described.

To Reproduce

Expected behavior

Sample project

https://github.com/OzymandiasTheGreat/nativescript-ngfor-bug
It's the ng-blank template with an additional child component. Just running the example prints what I'm describing.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions