diff --git a/modules/angular2/src/core/directives/ng_for.ts b/modules/angular2/src/core/directives/ng_for.ts index 5b1ad6ee89..726f0099fb 100644 --- a/modules/angular2/src/core/directives/ng_for.ts +++ b/modules/angular2/src/core/directives/ng_for.ts @@ -9,7 +9,8 @@ import {isPresent, isBlank} from 'angular2/src/core/facade/lang'; * to the current item from the iterable. * * It is possible to alias the `index` to a local variable that will be set to the current loop - * iteration in the template context. + * iteration in the template context, and also to alias the 'last' to a local variable that will + * be set to a boolean indicating if the item is the last one in the iteration * * When the contents of the iterator changes, `NgFor` makes the corresponding changes to the DOM: * @@ -76,6 +77,10 @@ export class NgFor { for (var i = 0; i < insertTuples.length; i++) { this._perViewChange(insertTuples[i].view, insertTuples[i].record); } + + for (var i = 0, ilen = this.viewContainer.length; i < ilen; i++) { + this.viewContainer.get(i).setLocal('last', i === ilen - 1); + } } private _perViewChange(view, record) { diff --git a/modules/angular2/test/core/directives/ng_for_spec.ts b/modules/angular2/test/core/directives/ng_for_spec.ts index a0b3b46abb..205e9fa554 100644 --- a/modules/angular2/test/core/directives/ng_for_spec.ts +++ b/modules/angular2/test/core/directives/ng_for_spec.ts @@ -252,6 +252,25 @@ export function main() { }); })); + it('should display last item correctly', + inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { + var template = + '