0

i'm trying to get data from my api, the code for getting datas :

getList() {
    this.fileList = [];

    this._globalService.getUserFiles(this.userId)
      .then(files => {
        files.forEach(retFile => {
          this._globalService.getFileActions(retFile._id)
            .then(retActions => {
              this.fileList.push( {
                file: retFile,
                action: retActions
              });
            });
        });
      })
      .finally(() => {
        this.finish = true;
      });
  }

Call OnInit hook. After, my view is trying to show same that :

<ng-container *ngIf="finish; else wait">
      <ng-container *ngIf="fileList.length; else noItems">
        <li *ngFor="let item of fileList">
         ...
        </li>
      <ng-container>
      <ng-template #noItems>
        <span class="noItems">Any file</span>
      </ng-template>
<ng-container>

That works fine. But my problem lasts a few seconds the #noItems template is to show when datas exists, like in this example :

enter image description here

1 Answer 1

1

You always push your result into this.FileList, you this.FileList never empty, therefore your noItem template never show up.

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

2 Comments

The array is emptied at init with this line : this.fileList = [];
The problem it's: when array is not empty (like my gif example) the #noItems template is show, his should not

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.