Do I use NgFor or NgForOf?

The angular API documentation says that instead of NgFor with version 4.0 onwards, use NgForOf instead of NgFor . But the Basics and the Heroic tutorial , the documentation demonstrates NgFor and does not mention NgForOf .

Is there anyone who can clarify this for me? Thank you in advance.

+5
source share
3 answers

They just renamed the class. NgForOf is a new class, NgFor now only an alias and will eventually disappear. https://github.com/angular/angular/blob/09d9f5fe54e7108c47de61393e10712f8239d824/packages/common/src/directives/ng_for_of.ts#L205

This only affects you if you use the link to the NgFor class in your code. The directive is imported using the CommonModule . The selector does not change, so if you use only NgFor in your template, nothing will change.

+6
source

ngForOf is the name of the class that implements the * ngFor directive. It was the type of class that changed (from ngFor to ngForOf), and not the directive itself. Therefore, in our templates we still use * ngFor.

+3
source

The difference that I see

[NgForOf] is used to assign the original value of the target in any tag. ngForOf is support for the NgFor class. At ngForOf, we assign our iteration array. ngForOf: NgIterable

[ngFor] does not require a type. Using this will mean that prop NgForOf is ngForOf: any

0
source

Source: https://habr.com/ru/post/1269484/


All Articles