Search code examples
angularangular6ngforangular-template

Fixing Dash in Words When Iterating in *ngFor in Angular


I have to iterate non-product in *ngFor but it doesnt accept the -
It can only accept _ but in -

How would you be able to fix this?

*ngFor="let product of products?.non-product

Solution

  • Use bracket notation since key property name is not a valid identifier.

    *ngFor="let product of products['non-product']"