Skip to content

Commit 35a83b4

Browse files
PatrickJSrkirov
authored andcommitted
feat(query_list): delegate toString to _results array
Closes angular#3004
1 parent dfe0130 commit 35a83b4

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

modules/angular2/src/core/compiler/query_list.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class QueryList<T> extends Object
108108
int get length => _results.length;
109109
T get first => _results.first;
110110
T get last => _results.last;
111+
String toString() {
112+
return _results.toString();
113+
}
111114

112115
List map(fn(T)) {
113116
// Note: we need to return a list instead of iterable to match JS.

modules/angular2/src/core/compiler/query_list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export class QueryList<T> {
9797

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

100+
toString(): string { return this._results.toString(); }
101+
100102
get length(): number { return this._results.length; }
101103
get first(): T { return ListWrapper.first(this._results); }
102104
get last(): T { return ListWrapper.last(this._results); }

modules/angular2/test/core/compiler/query_list_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';
22

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

67

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

47+
it('should support toString', () => {
48+
queryList.add('one');
49+
queryList.add('two');
50+
var listString = queryList.toString();
51+
expect(StringWrapper.contains(listString, 'one')).toBeTruthy();
52+
expect(StringWrapper.contains(listString, 'two')).toBeTruthy();
53+
});
54+
4655
it('should support first and last', () => {
4756
queryList.add('one');
4857
queryList.add('two');

0 commit comments

Comments
 (0)