|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {AfterContentInit, ElementRef, NgZone, OnDestroy, QueryList} from '@angular/core'; |
| 9 | +import {ElementRef, NgZone, OnDestroy, QueryList} from '@angular/core'; |
10 | 10 | import {setLines} from '@angular/material/core';
|
11 | 11 | import {Subscription} from 'rxjs';
|
12 |
| -import {startWith} from 'rxjs/operators'; |
13 | 12 |
|
14 | 13 | export class MatListBase {}
|
15 | 14 |
|
16 |
| -export class MatListItemBase implements AfterContentInit, OnDestroy { |
| 15 | +export class MatListItemBase implements OnDestroy { |
17 | 16 | lines: QueryList<ElementRef<Element>>;
|
18 | 17 |
|
19 | 18 | private _subscriptions = new Subscription();
|
20 | 19 |
|
21 |
| - constructor(protected _element: ElementRef, protected _ngZone: NgZone) {} |
| 20 | + constructor(protected _element: ElementRef, protected _ngZone: NgZone) { |
| 21 | + this._monitorLines(); |
| 22 | + } |
22 | 23 |
|
23 |
| - ngAfterContentInit() { |
| 24 | + /** |
| 25 | + * Subscribes to changes in `MatLine` content children and annotates them appropriately when they |
| 26 | + * change. |
| 27 | + */ |
| 28 | + private _monitorLines() { |
24 | 29 | this._ngZone.runOutsideAngular(() => {
|
25 |
| - this._subscriptions.add(this.lines.changes.pipe(startWith(this.lines)) |
26 |
| - .subscribe((lines: QueryList<ElementRef<Element>>) => { |
| 30 | + this._subscriptions.add( |
| 31 | + this.lines.changes.subscribe((lines: QueryList<ElementRef<Element>>) => { |
27 | 32 | lines.forEach((line: ElementRef<Element>, index: number) => {
|
28 | 33 | line.nativeElement.classList.toggle('mdc-list-item__primary-text', index === 0);
|
29 | 34 | line.nativeElement.classList.toggle('mdc-list-item__secondary-text', index !== 0);
|
|
0 commit comments