0

I'm trying to refactor my code

<ng-container *ngIf='taskOutputs$ | async as taskOutputs && taskOutputs.outputs.length; else neverImportedOrLoading'>

I'm getting Unexpected token &&, expected identifier

Should I absolutely split this in a child ng-container HTML item ? like bellow ?

<ng-container *ngIf='taskOutputs$ | async as taskOutputs && taskOutputs.outputs.length; else neverImportedOrLoading'>
  <ng-container taskOutputs.outputs.length; else neverImportedOrLoading'>
  </ng-container>
</ng-container>

Edit

Doing it this way (adding () )

<ng-container *ngIf='(taskOutputs$ | async as taskOutputs) && taskOutputs.outputs.length; else neverImportedOrLoading'>

got another error:

Missing expected ) at column 23 in [(taskOutputs$ | async as taskOutputs) && taskOutputs.outputs.length; else neverImportedOrLoading]
2
  • Try (taskOutputs$ | async as taskOutputs) Commented Feb 18, 2021 at 15:41
  • I get Missing expected ) at column 23 in [(taskOutputs$ | async as taskOutputs) && taskOutputs.outputs.length; else neverImportedOrLoading] Commented Feb 18, 2021 at 15:45

1 Answer 1

2

I suggested use two ng-container

<ng-container *ngIf='{tasks:taskOutputs$ | async} as data'>
   <ng-container *ngIf="data.tasks && data.tasks.length else neverImportedOrLoading">
        ...see that you need use data.tasks.., e.g.
        <div *ngFor="let task of data.tasks">
             {{task.taskId}}
        </div>
   </ng-container>
</ng-container>

See that the first condition {task:taskOutputs$|async} it's always fulfilled

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

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.