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:
Alfonso Presa
2015-09-04 16:59:04 +02:00
committed by Alfonso Presa
parent 2384082b5c
commit be954115f8
2 changed files with 25 additions and 1 deletions

View File

@ -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();
});
}));
});
}