Skip to content

Commit c7c199a

Browse files
committed
Revert "Revert "docs(material/table): use declarative idiomatic RxJS in table-http-example (angular#22053)" (angular#22725)"
- this reverts commit 9295ce5 - add `detectChanges()` call to fix `NG0100: ExpressionChangedAfterItHasBeenCheckedError`
1 parent 23dfbbb commit c7c199a

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

scripts/shim-scss-imports.js

100755100644
File mode changed.

src/components-examples/material/table/table-http/table-http-example.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.example-table-container {
77
position: relative;
88
min-height: 200px;
9-
max-height: 400px;
9+
height: 400px;
1010
overflow: auto;
1111
}
1212

src/components-examples/material/table/table-http/table-http-example.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
<div class="example-table-container">
1111

12-
<table mat-table [dataSource]="data" class="example-table"
13-
matSort matSortActive="created" matSortDisableClear matSortDirection="desc">
12+
<table mat-table [dataSource]="filteredAndPagedIssues" class="example-table" matSort
13+
matSortActive="created" matSortDisableClear matSortDirection="desc"
14+
(matSortChange)="resetPaging()">
1415
<!-- Number Column -->
1516
<ng-container matColumnDef="number">
1617
<th mat-header-cell *matHeaderCellDef>#</th>

src/components-examples/material/table/table-http/table-http-example.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {HttpClient} from '@angular/common/http';
2-
import {Component, ViewChild, AfterViewInit} from '@angular/core';
2+
import {Component, ViewChild, AfterViewInit, ChangeDetectorRef} from '@angular/core';
33
import {MatPaginator} from '@angular/material/paginator';
44
import {MatSort, SortDirection} from '@angular/material/sort';
55
import {merge, Observable, of as observableOf} from 'rxjs';
@@ -16,7 +16,7 @@ import {catchError, map, startWith, switchMap} from 'rxjs/operators';
1616
export class TableHttpExample implements AfterViewInit {
1717
displayedColumns: string[] = ['created', 'state', 'number', 'title'];
1818
exampleDatabase: ExampleHttpDatabase | null;
19-
data: GithubIssue[] = [];
19+
filteredAndPagedIssues: Observable<GithubIssue[]>;
2020

2121
resultsLength = 0;
2222
isLoadingResults = true;
@@ -25,15 +25,12 @@ export class TableHttpExample implements AfterViewInit {
2525
@ViewChild(MatPaginator) paginator: MatPaginator;
2626
@ViewChild(MatSort) sort: MatSort;
2727

28-
constructor(private _httpClient: HttpClient) {}
28+
constructor(private _httpClient: HttpClient, private _changeDetectorRef: ChangeDetectorRef) {}
2929

3030
ngAfterViewInit() {
3131
this.exampleDatabase = new ExampleHttpDatabase(this._httpClient);
3232

33-
// If the user changes the sort order, reset back to the first page.
34-
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
35-
36-
merge(this.sort.sortChange, this.paginator.page)
33+
this.filteredAndPagedIssues = merge(this.sort.sortChange, this.paginator.page)
3734
.pipe(
3835
startWith({}),
3936
switchMap(() => {
@@ -57,7 +54,12 @@ export class TableHttpExample implements AfterViewInit {
5754
this.resultsLength = data.total_count;
5855
return data.items;
5956
})
60-
).subscribe(data => this.data = data);
57+
);
58+
this._changeDetectorRef.detectChanges();
59+
}
60+
61+
resetPaging(): void {
62+
this.paginator.pageIndex = 0;
6163
}
6264
}
6365

0 commit comments

Comments
 (0)