Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/angular2/src/core/compiler/query_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class QueryList<T> extends Object with IterableMixin<T> implements IQueryList<T>
int get length => _results.length;
T get first => _results.first;
T get last => _results.last;
String toString() {
return _results.toString();
}

List map(fn(T)) {
// Note: we need to return a list instead of iterable to match JS.
Expand Down
2 changes: 2 additions & 0 deletions modules/angular2/src/core/compiler/query_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export class QueryList<T> implements IQueryList<T> {

removeCallback(callback: () => void): void { ListWrapper.remove(this._callbacks, callback); }

toString(): string { return this._results.toString(); }

get length(): number { return this._results.length; }
get first(): T { return ListWrapper.first(this._results); }
get last(): T { return ListWrapper.last(this._results); }
Expand Down
9 changes: 9 additions & 0 deletions modules/angular2/test/core/compiler/query_list_spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';

import {List, MapWrapper, ListWrapper, iterateListLike} from 'angular2/src/facade/collection';
import {StringWrapper} from 'angular2/src/facade/lang';
import {QueryList} from 'angular2/src/core/compiler/query_list';


Expand Down Expand Up @@ -43,6 +44,14 @@ export function main() {
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
});

it('should support toString', () => {
queryList.add('one');
queryList.add('two');
var listString = queryList.toString();
expect(StringWrapper.contains(listString, 'one')).toBeTruthy();
expect(StringWrapper.contains(listString, 'two')).toBeTruthy();
});

it('should support first and last', () => {
queryList.add('one');
queryList.add('two');
Expand Down