6

In the angular API documentation it says to use NgForOf instead of NgFor with version 4.0 onwards. But the Fundamentals, and Heroes tutorial, documentation demonstrateNgFor, and make no mention of NgForOf.

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

  • 1
    `*ngFor` is the sugar-coated version of `ngForOf` (https://stackoverflow.com/questions/43388893/what-is-the-difference-between-ngfor-and-ngforof-in-angular2) and as you've said it appears that `*ngFor` is now deprecated so it is better to use `ngForOf` – eko Jul 04 '17 at 14:55

3 Answers3

8

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

This only affects you if you are using a reference to the NgFor class in your code. The directive is imported using the CommonModule. The selector is unchanged, therefore if you are only using ngFor in your template, nothing will change.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
4

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

DeborahK
  • 57,520
  • 12
  • 104
  • 129
1

The difference I see

[NgForOf] is used to assign a source value into a target within any tag. ngForOf is a prop of NgFor class. In ngForOf we assign our array to iterate. ngForOf : NgIterable

[ngFor] doesn't require a type. Using this will mean the prop NgForOf is ngForOf : any