Skip to content

Commit 47b73fd

Browse files
emilio-martinezmhevery
authored andcommitted
fix(core): ensure initial value of QueryList length (#21980) (#21982)
Set initial value of `length` to `0`. Fixes regression introduced by e544742#diff-a85dbe0991a7577ea24b49374e9ae90b where the `length` property ceased to have initial value. Closes #21980 PR Close #21982
1 parent 07769e5 commit 47b73fd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/core/src/linker/query_list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class QueryList<T>/* implements Iterable<T> */ {
4141
private _results: Array<T> = [];
4242
public readonly changes: Observable<any> = new EventEmitter();
4343

44-
readonly length: number;
44+
readonly length: number = 0;
4545
readonly first: T;
4646
readonly last: T;
4747

packages/core/test/linker/query_list_spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
2323

2424
function logAppend(item: any /** TODO #9100 */) { log += (log.length == 0 ? '' : ', ') + item; }
2525

26+
describe('dirty and reset', () => {
27+
28+
it('should initially be dirty and empty', () => {
29+
expect(queryList.dirty).toBeTruthy();
30+
expect(queryList.length).toBe(0);
31+
});
32+
33+
it('should be not dirty after reset', () => {
34+
expect(queryList.dirty).toBeTruthy();
35+
queryList.reset(['one', 'two']);
36+
expect(queryList.dirty).toBeFalsy();
37+
expect(queryList.length).toBe(2);
38+
});
39+
40+
});
41+
2642
it('should support resetting and iterating over the new objects', () => {
2743
queryList.reset(['one']);
2844
queryList.reset(['two']);

0 commit comments

Comments
 (0)