Skip to content

docs: reduce reliance on static queries in live examples #20452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
})
export class CdkPortalOverviewExample implements AfterViewInit {
@ViewChild('templatePortalContent') templatePortalContent: TemplateRef<unknown>;
@ViewChild('domPortalContent', {static: true}) domPortalContent: ElementRef<HTMLElement>;
@ViewChild('domPortalContent') domPortalContent: ElementRef<HTMLElement>;

selectedPortal: Portal<any>;
componentPortal: ComponentPortal<ComponentPortalExample>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {AfterViewInit, Component, ViewChild} from '@angular/core';
import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
Expand Down Expand Up @@ -28,12 +28,12 @@ const NAMES: string[] = [
styleUrls: ['table-overview-example.css'],
templateUrl: 'table-overview-example.html',
})
export class TableOverviewExample implements OnInit {
export class TableOverviewExample implements AfterViewInit {
displayedColumns: string[] = ['id', 'name', 'progress', 'color'];
dataSource: MatTableDataSource<UserData>;

@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild(MatSort, {static: true}) sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;

constructor() {
// Create 100 users
Expand All @@ -43,7 +43,7 @@ export class TableOverviewExample implements OnInit {
this.dataSource = new MatTableDataSource(users);
}

ngOnInit() {
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {AfterViewInit, Component, ViewChild} from '@angular/core';
import {MatPaginator} from '@angular/material/paginator';
import {MatTableDataSource} from '@angular/material/table';

Expand All @@ -10,13 +10,13 @@ import {MatTableDataSource} from '@angular/material/table';
styleUrls: ['table-pagination-example.css'],
templateUrl: 'table-pagination-example.html',
})
export class TablePaginationExample implements OnInit {
export class TablePaginationExample implements AfterViewInit {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);

@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild(MatPaginator) paginator: MatPaginator;

ngOnInit() {
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {AfterViewInit, Component, ViewChild} from '@angular/core';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';

Expand Down Expand Up @@ -30,13 +30,13 @@ const ELEMENT_DATA: PeriodicElement[] = [
styleUrls: ['table-sorting-example.css'],
templateUrl: 'table-sorting-example.html',
})
export class TableSortingExample implements OnInit {
export class TableSortingExample implements AfterViewInit {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource(ELEMENT_DATA);

@ViewChild(MatSort, {static: true}) sort: MatSort;
@ViewChild(MatSort) sort: MatSort;

ngOnInit() {
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Component,
ContentChildren,
Input,
OnInit,
AfterViewInit,
QueryList,
ViewChild
} from '@angular/core';
Expand Down Expand Up @@ -45,13 +45,13 @@ const ELEMENT_DATA: PeriodicElement[] = [
styleUrls: ['table-wrapped-example.css'],
templateUrl: 'table-wrapped-example.html',
})
export class TableWrappedExample implements OnInit {
export class TableWrappedExample implements AfterViewInit {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);

@ViewChild('sort', {static: true}) sort: MatSort;
@ViewChild('sort') sort: MatSort;

ngOnInit() {
ngAfterViewInit() {
this.dataSource.sort = this.sort;
}
}
Expand Down