D
D
Denis Shcherbina2022-02-22 10:08:54
Angular
Denis Shcherbina, 2022-02-22 10:08:54

Why don't ngIf and ngFor work dynamically on server pre-render?

When server rendering, ngIf and ngFor do not pick up variable changes. They take the initial values ​​of the variables and in the further dynamic change do not change the page display (in my case, the list output). If you make a button and an event on it (click)="", then everything works.

data: any;
async getSpecificData() {
    // подгружаем данные из сервиса. 
    this.data = await this.feedService.get_specific_tovar()
     // В переменной data - данные есть по результату, но ngFor её не обновляет.
    console.log('Закончил загрузку');
    this.status_loader = false;
}

<ng-container *ngIf="status_loader">
        <h1>СТРАНИЦА ЗАГРУЖАЕТСЯ </h1>
    </ng-container>
    <ng-container *ngIf="!status_loader">
          <ng-container *ngFor="let item of data; let i = index">
               <h1>{{item}}</h1>
          </ng-container>
    </ng-container>

For server rendering I use: angular universal
Angular version: 13.2.0

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question