S
S
Stanislav Pyryaev2019-04-08 22:46:42
Angular
Stanislav Pyryaev, 2019-04-08 22:46:42

How to display the size of the edited *ngFor array in another (previous) html block?

There is a component template:

<div >
    <!-- Загружаем список ошибок -->
    <div *ngFor="let error of errors">
      <div>
        <h4>{{error.name}}</h4>
        <p>(кол-во: {{Здесь нужно отобразить размер массива items, полученный ниже}})</p>
      </div>

      <!-- Загружаем для каждой ошибки свой список данных отсортированный пайпом -->
      <div>
        <div *ngFor="let item of items | sortItemsByError:error; let l = count">
          <a [routerLink]="['/items/',item.id]">{{item.name}}</a>          
        </div>
      </div>
    </div>
  </div>

Tell me how to display the size of the current array "l" in the paragraph above, if the paragraph is not included in the block where this array is listed.
You need to get something in the form of a structure:
Error 1 (number: 4)
-item1;
-item2;
-item3;
-item4;
Error 2 (number: 2)
-item1;
-item2;
etc....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-04-08
@Sjupj

{{ items.length }}don't you?
Generally speaking, you can use the template context to pass a value into a template.
like this
https://stackblitz.com/edit/angular-xkuwzk
you can also use a crutch in the form of a let (or var) directive (or ngIf)
sketched: https://stackblitz.com/edit/angular-mwqwws
but better just upon receipt of data, process them and save them in a separate variable, and already refer to it in the template.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question