This how you can do it :
<md-expansion-panel
*ngFor="let item of items; let first = first; let last = last"
[ngClass]="{ 'first' : first }">
<content></content>
</md-expansion-panel>
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 so it start from 0.
first
will be set to a boolean value indicating whether the item is
the first one in the iteration.
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.
for more information : NgFor-directive
a complete example
<div
*ngFor="let n of items; let itemsCount = count;let idx = index , let isOdd = odd;let first = first ;let last = last;">
{{n}} ,
{{itemsCount}} ,
{{idx}} ,
odd π {{isOdd}} ,
first π {{first}} ,
last π {{last}}
</div>
demo
last
,first
etc. Thank you, you are star! β Roughneck