1

How can I force my view to render null values into the template as a blank space?

<table>
  <tr *ngFor="let key of keys">
    <!-- may evaluate to null but I want the row anyway -->
    <td>{{ foo[key]}}</td>
  </tr>
</table>

2 Answers 2

1

The null value is output as empty content, which collapses the cell. The same thing happens if the cell contains only space characters. To get a non-collapsed cell, you can insert an unbreakable space in it when the value is null:

<td>{{ foo[key] || "&nbsp;" }}</td>

See this stackblitz.

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

Comments

0

Straight-forward solution for this that I've used many times:

<td>{{ (foo[key] || '') }}</td>

1 Comment

I believe this renders nothing, not an empty td

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.