A
A
avikik2020-04-20 18:22:17
JavaScript
avikik, 2020-04-20 18:22:17

Can't access UI field in Angular?

Good day to all!
A very funny thing happened with the interface in Angular.
According to the Angular style guide, I created several models on interfaces (although I always did it on classes).
Here is the code:

export interface Car {
  id?: string;
  name: string;
}
export interface CarsBlock {
  carsMarks: string;
  cars: Car [];
}

export interface CarsBlockPage {
  CarsBlockList: CarsBlock[];
}


And so I get a great json from the server and fill my model with it.
That's just what's funny. When I start throwing it in *ngFor
<div *ngFor="let carsBlock of CarsBlockPage.CarsBlockList">
  <app-cars-block [carsBlock]="carsBlock"></app-cars-block>
</div>

He swears and says that he only works with an array! and writes undefind type
But if I remove CarsBlockList
<div *ngFor="let carsBlock of CarsBlockPage">
  <app-cars-block [carsBlock]="carsBlock"></app-cars-block>
</div>

Everything works fine and he takes it for a regular collection.

I also wanted to unshift the given collection.
CarsBlockPage.CarsBlockList.unshift(carBlock);

It says that it doesn't have such a method! And I can't access this collection by index.
But if I write: It gives me the 1st element of the collection! Guys, what the hell is going on? It seemed to mutate and become a collection itself, which does not have its methods)
CarsBlockPage[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