Implementing ngClassEven ngClassOdd for angular 2

前端 未结 3 1178
闹比i
闹比i 2020-12-19 01:52

I tried to implement ng-class-even and ng-class-odd ( from angular 1) type behaviour in angular 2 application.

I have written the code below and its working fine, I

3条回答
  •  独厮守ぢ
    2020-12-19 02:45

    update (Angular4)

    original (Angular2)

    This should work:

    {{employee.name}}

    NgFor provides several exported values that can be aliased to local variables:

    • index will be set to the current loop iteration for each template context.
    • first will be set to a boolean value indicating whether the item is the first one in the iteration. (since beta.15)
    • last will be set to a boolean value indicating whether the item is the last one in the iteration.
    • even will be set to a boolean value indicating whether this item has an even index.
    • odd will be set to a boolean value indicating whether this item has an odd index.

    Plunker

    See also https://angular.io/docs/ts/latest/api/common/index/NgFor-directive.html

提交回复
热议问题