0

There is an array:

var stringArray = new Array();
stringArray[1] = 'one';

And ngFor renders nothing in angular when stringArray[0] = undefined.

How do I solve it?

1
  • Are you intentionally trying to avoid initialising the array with falsy values like null? Commented Feb 25, 2021 at 22:33

2 Answers 2

1

That should work fine. I used ng-container for loop with ngFor and ngIf in a < li >
I was able to replicate that in stackblitz here is the link:

https://stackblitz.com/edit/angular-a2xph9?file=src%2Fapp%2Fapp.component.html

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to exclude undefined, null and empty values from your template, you could simply filter your data source:

  private source = [
    undefined, 
    null, 
    "", 
    "Hello World"
  ];

  public stringArray = source.filter(i => i);

StackBlitz

screenshot of filtered output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.