feat(NgFor): $last property support
Makes a new `$last` property available during the loop with a boolean showing if it's the last item in the iteration. closes: #3102 Closes #3991
This commit is contained in:

committed by
Alfonso Presa

parent
2384082b5c
commit
be954115f8
@ -252,6 +252,25 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display last item correctly',
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
var template =
|
||||
'<div><copy-me template="ng-for: var item of items; var isLast=last">{{isLast.toString()}}</copy-me></div>';
|
||||
|
||||
tcb.overrideTemplate(TestComponent, template)
|
||||
.createAsync(TestComponent)
|
||||
.then((rootTC) => {
|
||||
rootTC.componentInstance.items = [0, 1, 2];
|
||||
rootTC.detectChanges();
|
||||
expect(rootTC.nativeElement).toHaveText('falsefalsetrue');
|
||||
|
||||
rootTC.componentInstance.items = [2, 1];
|
||||
rootTC.detectChanges();
|
||||
expect(rootTC.nativeElement).toHaveText('falsetrue');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user