0

I have a ternary statement in an Angular HTML template. But when the statement returns false, the data is not distributed to all 6 columns.

<td colspan="getNrOfColumnHeaders() ? 8 : 6">
    {{(serverError ? 'SERVER_ERROR_TABLE_MSG' : 'NO_DATA') | translate}}
</td>

Anyone any idea what is going wrong?

1
  • 3
    You aren't binding to that attribute. Look in dev tools, you'll probably see you're setting the literal value getNrOfColumnHeaders() ? 8 : 6. Commented Nov 6, 2018 at 9:31

2 Answers 2

6

You need to bind to the attribute dynamically so that Angular knows it has to update the value when it changes, so you need [colspan] instead of colspan:

<td [colspan]="getNrOfColumnHeaders() ? 8 : 6">
  {{(serverError ? 'SERVER_ERROR_TABLE_MSG' : 'NO_DATA') | translate}}
</td>
Sign up to request clarification or add additional context in comments.

Comments

1

Be sure that getNrOfColumnHeaders return boolean and add brackets to colsap attribute like this.

 <td [attr.colspan]="getNrOfColumnHeaders() ? 8 : 6">
          {{(serverError ? 'SERVER_ERROR_TABLE_MSG' : 'NO_DATA') | translate}}
    </td>

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.