Updated Angular Material element examples

This commit is contained in:
Sercan Yemen 2018-08-28 07:53:09 +03:00
parent 8fc20fef8f
commit 62b64cb78c
116 changed files with 934 additions and 898 deletions

View File

@ -3,7 +3,7 @@
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto"> <input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete autoActiveFirstOption #auto="matAutocomplete"> <mat-autocomplete autoActiveFirstOption #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option"> <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option }} {{option}}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>

View File

@ -9,22 +9,23 @@ import {map, startWith} from 'rxjs/operators';
@Component({ @Component({
selector: 'autocomplete-auto-active-first-option-example', selector: 'autocomplete-auto-active-first-option-example',
templateUrl: 'autocomplete-auto-active-first-option-example.html', templateUrl: 'autocomplete-auto-active-first-option-example.html',
styleUrls: ['autocomplete-auto-active-first-option-example.css'] styleUrls: ['autocomplete-auto-active-first-option-example.css'],
}) })
export class AutocompleteAutoActiveFirstOptionExample implements OnInit { export class AutocompleteAutoActiveFirstOptionExample implements OnInit {
myControl: FormControl = new FormControl(); myControl = new FormControl();
options = ['One', 'Two', 'Three']; options: string[] = ['One', 'Two', 'Three'];
filteredOptions: Observable<string[]>; filteredOptions: Observable<string[]>;
ngOnInit() { ngOnInit() {
this.filteredOptions = this.myControl.valueChanges.pipe( this.filteredOptions = this.myControl.valueChanges.pipe(
startWith(''), startWith(''),
map(val => this.filter(val)) map(value => this._filter(value))
); );
} }
filter(val: string): string[] { private _filter(value: string): string[] {
return this.options.filter(option => option.toLowerCase().indexOf(val.toLowerCase()) === 0); const filterValue = value.toLowerCase();
}
return this.options.filter(option => option.toLowerCase().indexOf(filterValue) === 0);
}
} }

View File

@ -3,7 +3,7 @@
<input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto"> <input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn"> <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option"> <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option.name }} {{option.name}}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>

View File

@ -3,8 +3,8 @@ import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators'; import {map, startWith} from 'rxjs/operators';
export class User { export interface User {
constructor(public name: string) { } name: string;
} }
/** /**
@ -13,18 +13,15 @@ export class User {
@Component({ @Component({
selector: 'autocomplete-display-example', selector: 'autocomplete-display-example',
templateUrl: 'autocomplete-display-example.html', templateUrl: 'autocomplete-display-example.html',
styleUrls: ['autocomplete-display-example.css'] styleUrls: ['autocomplete-display-example.css'],
}) })
export class AutocompleteDisplayExample implements OnInit { export class AutocompleteDisplayExample implements OnInit {
myControl = new FormControl(); myControl = new FormControl();
options: User[] = [
options = [ {name: 'Mary'},
new User('Mary'), {name: 'Shelley'},
new User('Shelley'), {name: 'Igor'}
new User('Igor')
]; ];
filteredOptions: Observable<User[]>; filteredOptions: Observable<User[]>;
ngOnInit() { ngOnInit() {
@ -32,17 +29,17 @@ export class AutocompleteDisplayExample implements OnInit {
.pipe( .pipe(
startWith<string | User>(''), startWith<string | User>(''),
map(value => typeof value === 'string' ? value : value.name), map(value => typeof value === 'string' ? value : value.name),
map(name => name ? this.filter(name) : this.options.slice()) map(name => name ? this._filter(name) : this.options.slice())
); );
} }
filter(name: string): User[] {
return this.options.filter(option =>
option.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
}
displayFn(user?: User): string | undefined { displayFn(user?: User): string | undefined {
return user ? user.name : undefined; return user ? user.name : undefined;
} }
private _filter(name: string): User[] {
const filterValue = name.toLowerCase();
return this.options.filter(option => option.name.toLowerCase().indexOf(filterValue) === 0);
}
} }

View File

@ -3,7 +3,7 @@
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto"> <input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete"> <mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option"> <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option }} {{option}}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>

View File

@ -9,31 +9,24 @@ import {map, startWith} from 'rxjs/operators';
@Component({ @Component({
selector: 'autocomplete-filter-example', selector: 'autocomplete-filter-example',
templateUrl: 'autocomplete-filter-example.html', templateUrl: 'autocomplete-filter-example.html',
styleUrls: ['autocomplete-filter-example.css'] styleUrls: ['autocomplete-filter-example.css'],
}) })
export class AutocompleteFilterExample implements OnInit { export class AutocompleteFilterExample implements OnInit {
myControl = new FormControl();
myControl: FormControl = new FormControl(); options: string[] = ['One', 'Two', 'Three'];
options = [
'One',
'Two',
'Three'
];
filteredOptions: Observable<string[]>; filteredOptions: Observable<string[]>;
ngOnInit() { ngOnInit() {
this.filteredOptions = this.myControl.valueChanges this.filteredOptions = this.myControl.valueChanges
.pipe( .pipe(
startWith(''), startWith(''),
map(val => this.filter(val)) map(value => this._filter(value))
); );
} }
filter(val: string): string[] { private _filter(value: string): string[] {
return this.options.filter(option => const filterValue = value.toLowerCase();
option.toLowerCase().includes(val.toLowerCase()));
}
return this.options.filter(option => option.toLowerCase().includes(filterValue));
}
} }

View File

@ -1,10 +1,10 @@
<form [formGroup]="stateForm"> <form [formGroup]="stateForm">
<mat-form-field> <mat-form-field>
<input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup"/> <input type="text" matInput placeholder="States Group" formControlName="stateGroup" required [matAutocomplete]="autoGroup">
<mat-autocomplete #autoGroup="matAutocomplete"> <mat-autocomplete #autoGroup="matAutocomplete">
<mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter"> <mat-optgroup *ngFor="let group of stateGroupOptions | async" [label]="group.letter">
<mat-option *ngFor="let name of group.names" [value]="name"> <mat-option *ngFor="let name of group.names" [value]="name">
{{ name }} {{name}}
</mat-option> </mat-option>
</mat-optgroup> </mat-optgroup>
</mat-autocomplete> </mat-autocomplete>

View File

@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {FormGroup, FormBuilder} from '@angular/forms'; import {FormBuilder, FormGroup} from '@angular/forms';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {startWith, map} from 'rxjs/operators'; import {startWith, map} from 'rxjs/operators';
@ -8,6 +8,12 @@ export interface StateGroup {
names: string[]; names: string[];
} }
export const _filter = (opt: string[], value: string): string[] => {
const filterValue = value.toLowerCase();
return opt.filter(item => item.toLowerCase().indexOf(filterValue) === 0);
};
/** /**
* @title Option groups autocomplete * @title Option groups autocomplete
*/ */
@ -84,28 +90,23 @@ export class AutocompleteOptgroupExample implements OnInit {
stateGroupOptions: Observable<StateGroup[]>; stateGroupOptions: Observable<StateGroup[]>;
constructor(private fb: FormBuilder) { } constructor(private fb: FormBuilder) {}
ngOnInit() { ngOnInit() {
this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges this.stateGroupOptions = this.stateForm.get('stateGroup')!.valueChanges
.pipe( .pipe(
startWith(''), startWith(''),
map(val => this.filterGroup(val)) map(value => this._filterGroup(value))
); );
} }
filterGroup(val: string): StateGroup[] { private _filterGroup(value: string): StateGroup[] {
if (val) { if (value) {
return this.stateGroups return this.stateGroups
.map(group => ({ letter: group.letter, names: this._filter(group.names, val) })) .map(group => ({letter: group.letter, names: _filter(group.names, value)}))
.filter(group => group.names.length > 0); .filter(group => group.names.length > 0);
} }
return this.stateGroups; return this.stateGroups;
} }
private _filter(opt: string[], val: string) {
const filterValue = val.toLowerCase();
return opt.filter(item => item.toLowerCase().startsWith(filterValue));
}
} }

View File

@ -7,3 +7,13 @@
.example-full-width { .example-full-width {
width: 100%; width: 100%;
} }
.example-option-img {
vertical-align: middle;
margin-right: 8px;
}
[dir='rtl'] .example-option-img {
margin-right: 0;
margin-left: 8px;
}

View File

@ -3,14 +3,14 @@
<input matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl"> <input matInput placeholder="State" aria-label="State" [matAutocomplete]="auto" [formControl]="stateCtrl">
<mat-autocomplete #auto="matAutocomplete"> <mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let state of filteredStates | async" [value]="state.name"> <mat-option *ngFor="let state of filteredStates | async" [value]="state.name">
<img style="vertical-align:middle;" aria-hidden src="{{state.flag}}" height="25" /> <img class="example-option-img" aria-hidden [src]="state.flag" height="25">
<span>{{ state.name }}</span> | <span>{{state.name}}</span> |
<small>Population: {{state.population}}</small> <small>Population: {{state.population}}</small>
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>
<br /> <br>
<mat-slide-toggle <mat-slide-toggle
[checked]="stateCtrl.disabled" [checked]="stateCtrl.disabled"

View File

@ -1,11 +1,12 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {FormControl} from '@angular/forms'; import {FormControl} from '@angular/forms';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {map, startWith} from 'rxjs/operators'; import {map, startWith} from 'rxjs/operators';
export class State { export interface State {
constructor(public name: string, public population: string, public flag: string) { } flag: string;
name: string;
population: string;
} }
/** /**
@ -14,11 +15,11 @@ export class State {
@Component({ @Component({
selector: 'autocomplete-overview-example', selector: 'autocomplete-overview-example',
templateUrl: 'autocomplete-overview-example.html', templateUrl: 'autocomplete-overview-example.html',
styleUrls: ['autocomplete-overview-example.css'] styleUrls: ['autocomplete-overview-example.css'],
}) })
export class AutocompleteOverviewExample { export class AutocompleteOverviewExample {
stateCtrl: FormControl; stateCtrl = new FormControl();
filteredStates: Observable<any[]>; filteredStates: Observable<State[]>;
states: State[] = [ states: State[] = [
{ {
@ -48,17 +49,16 @@ export class AutocompleteOverviewExample {
]; ];
constructor() { constructor() {
this.stateCtrl = new FormControl();
this.filteredStates = this.stateCtrl.valueChanges this.filteredStates = this.stateCtrl.valueChanges
.pipe( .pipe(
startWith(''), startWith(''),
map(state => state ? this.filterStates(state) : this.states.slice()) map(state => state ? this._filterStates(state) : this.states.slice())
); );
} }
filterStates(name: string) { private _filterStates(value: string): State[] {
return this.states.filter(state => const filterValue = value.toLowerCase();
state.name.toLowerCase().indexOf(name.toLowerCase()) === 0);
}
return this.states.filter(state => state.name.toLowerCase().indexOf(filterValue) === 0);
}
} }

View File

@ -3,7 +3,7 @@
<input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto"> <input type="text" placeholder="Pick one" aria-label="Number" matInput [formControl]="myControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete"> <mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option"> <mat-option *ngFor="let option of options" [value]="option">
{{ option }} {{option}}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>

View File

@ -7,16 +7,9 @@ import {FormControl} from '@angular/forms';
@Component({ @Component({
selector: 'autocomplete-simple-example', selector: 'autocomplete-simple-example',
templateUrl: 'autocomplete-simple-example.html', templateUrl: 'autocomplete-simple-example.html',
styleUrls: ['autocomplete-simple-example.css'] styleUrls: ['autocomplete-simple-example.css'],
}) })
export class AutocompleteSimpleExample { export class AutocompleteSimpleExample {
myControl = new FormControl();
myControl: FormControl = new FormControl(); options: string[] = ['One', 'Two', 'Three'];
options = [
'One',
'Two',
'Three'
];
} }

View File

@ -1,12 +1,11 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
/** /**
* @title Badge overview * @title Badge overview
*/ */
@Component({ @Component({
selector: 'badge-overview-example', selector: 'badge-overview-example',
templateUrl: 'badge-overview-example.html', templateUrl: 'badge-overview-example.html',
styleUrls: ['badge-overview-example.css'] styleUrls: ['badge-overview-example.css'],
}) })
export class BadgeOverviewExample { } export class BadgeOverviewExample {}

View File

@ -1,5 +1,4 @@
.example-button-row { .button-row button,
display: flex; .button-row a {
align-items: center; margin-right: 8px;
justify-content: space-around;
} }

View File

@ -18,6 +18,26 @@
<a mat-raised-button routerLink=".">Link</a> <a mat-raised-button routerLink=".">Link</a>
</div> </div>
<h3>Stroked Buttons</h3>
<div class="button-row">
<button mat-stroked-button>Basic</button>
<button mat-stroked-button color="primary">Primary</button>
<button mat-stroked-button color="accent">Accent</button>
<button mat-stroked-button color="warn">Warn</button>
<button mat-stroked-button disabled>Disabled</button>
<a mat-stroked-button routerLink=".">Link</a>
</div>
<h3>Flat Buttons</h3>
<div class="button-row">
<button mat-flat-button>Basic</button>
<button mat-flat-button color="primary">Primary</button>
<button mat-flat-button color="accent">Accent</button>
<button mat-flat-button color="warn">Warn</button>
<button mat-flat-button disabled>Disabled</button>
<a mat-flat-button routerLink=".">Link</a>
</div>
<h3>Icon Buttons</h3> <h3>Icon Buttons</h3>
<div class="button-row"> <div class="button-row">
<button mat-icon-button> <button mat-icon-button>

View File

@ -2,24 +2,11 @@ import {DataSource} from '@angular/cdk/collections';
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs'; import {BehaviorSubject, Observable} from 'rxjs';
/**
* @title Basic use of `<cdk-table>` (uses display flex)
*/
@Component({
selector: 'cdk-table-basic-flex-example',
styleUrls: ['cdk-table-basic-flex-example.css'],
templateUrl: 'cdk-table-basic-flex-example.html',
})
export class CdkTableBasicFlexExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = new ExampleDataSource();
}
export interface PeriodicElement { export interface PeriodicElement {
name: string; name: string;
position: number; position: number;
weight: number;
symbol: string; symbol: string;
weight: number;
} }
const ELEMENT_DATA: PeriodicElement[] = [ const ELEMENT_DATA: PeriodicElement[] = [
@ -35,6 +22,19 @@ const ELEMENT_DATA: PeriodicElement[] = [
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]; ];
/**
* @title Basic use of `<cdk-table>` (uses display flex)
*/
@Component({
selector: 'cdk-table-basic-flex-example',
styleUrls: ['cdk-table-basic-flex-example.css'],
templateUrl: 'cdk-table-basic-flex-example.html',
})
export class CdkTableBasicFlexExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new ExampleDataSource();
}
/** /**
* Data source to provide what data should be rendered in the table. Note that the data source * Data source to provide what data should be rendered in the table. Note that the data source
* can retrieve its data in any way. In this case, the data source is provided a reference * can retrieve its data in any way. In this case, the data source is provided a reference
@ -44,7 +44,7 @@ const ELEMENT_DATA: PeriodicElement[] = [
*/ */
export class ExampleDataSource extends DataSource<PeriodicElement> { export class ExampleDataSource extends DataSource<PeriodicElement> {
/** Stream of data that is provided to the table. */ /** Stream of data that is provided to the table. */
data: BehaviorSubject<PeriodicElement[]> = new BehaviorSubject<PeriodicElement[]>(ELEMENT_DATA); data = new BehaviorSubject<PeriodicElement[]>(ELEMENT_DATA);
/** Connect function called by the table to retrieve one stream containing the data to render. */ /** Connect function called by the table to retrieve one stream containing the data to render. */
connect(): Observable<PeriodicElement[]> { connect(): Observable<PeriodicElement[]> {

View File

@ -2,19 +2,6 @@ import {DataSource} from '@angular/cdk/collections';
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {BehaviorSubject, Observable} from 'rxjs'; import {BehaviorSubject, Observable} from 'rxjs';
/**
* @title Basic CDK data-table
*/
@Component({
selector: 'cdk-table-basic-example',
styleUrls: ['cdk-table-basic-example.css'],
templateUrl: 'cdk-table-basic-example.html',
})
export class CdkTableBasicExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = new ExampleDataSource();
}
export interface PeriodicElement { export interface PeriodicElement {
name: string; name: string;
position: number; position: number;
@ -35,6 +22,19 @@ const ELEMENT_DATA: PeriodicElement[] = [
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]; ];
/**
* @title Basic CDK data-table
*/
@Component({
selector: 'cdk-table-basic-example',
styleUrls: ['cdk-table-basic-example.css'],
templateUrl: 'cdk-table-basic-example.html',
})
export class CdkTableBasicExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new ExampleDataSource();
}
/** /**
* Data source to provide what data should be rendered in the table. Note that the data source * Data source to provide what data should be rendered in the table. Note that the data source
* can retrieve its data in any way. In this case, the data source is provided a reference * can retrieve its data in any way. In this case, the data source is provided a reference
@ -44,7 +44,7 @@ const ELEMENT_DATA: PeriodicElement[] = [
*/ */
export class ExampleDataSource extends DataSource<PeriodicElement> { export class ExampleDataSource extends DataSource<PeriodicElement> {
/** Stream of data that is provided to the table. */ /** Stream of data that is provided to the table. */
data: BehaviorSubject<PeriodicElement[]> = new BehaviorSubject<PeriodicElement[]>(ELEMENT_DATA); data = new BehaviorSubject<PeriodicElement[]>(ELEMENT_DATA);
/** Connect function called by the table to retrieve one stream containing the data to render. */ /** Connect function called by the table to retrieve one stream containing the data to render. */
connect(): Observable<PeriodicElement[]> { connect(): Observable<PeriodicElement[]> {

View File

@ -1,4 +1,4 @@
.demo-tree-node { .example-tree-node {
display: flex; display: flex;
align-items: center; align-items: center;
} }

View File

@ -1,9 +1,9 @@
<cdk-tree [dataSource]="dataSource" [treeControl]="treeControl"> <cdk-tree [dataSource]="dataSource" [treeControl]="treeControl">
<cdk-tree-node *cdkTreeNodeDef="let node" cdkTreeNodePadding class="demo-tree-node"> <cdk-tree-node *cdkTreeNodeDef="let node" cdkTreeNodePadding class="example-tree-node">
<button mat-icon-button disabled></button> <button mat-icon-button disabled></button>
{{node.filename}}: {{node.type}} {{node.filename}}: {{node.type}}
</cdk-tree-node> </cdk-tree-node>
<cdk-tree-node *cdkTreeNodeDef="let node; when: hasChild" cdkTreeNodePadding class="demo-tree-node"> <cdk-tree-node *cdkTreeNodeDef="let node; when: hasChild" cdkTreeNodePadding class="example-tree-node">
<button mat-icon-button [attr.aria-label]="'toggle ' + node.filename" cdkTreeNodeToggle> <button mat-icon-button [attr.aria-label]="'toggle ' + node.filename" cdkTreeNodeToggle>
<mat-icon class="mat-icon-rtl-mirror"> <mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}} {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}

View File

@ -15,51 +15,48 @@ export class FileNode {
/** Flat node with expandable and level information */ /** Flat node with expandable and level information */
export class FileFlatNode { export class FileFlatNode {
filename: string; constructor(
type: any; public expandable: boolean, public filename: string, public level: number, public type: any) {}
level: number;
expandable: boolean;
} }
/** /**
* The file structure tree data in string. The data could be parsed into a Json object * The file structure tree data in string. The data could be parsed into a Json object
*/ */
const TREE_DATA = ` const TREE_DATA = JSON.stringify({
{ Applications: {
"Documents": { Calendar: 'app',
"angular": { Chrome: 'app',
"src": { Webstorm: 'app'
"core": "ts", },
"compiler": "ts" Documents: {
} angular: {
}, src: {
"material2": { compiler: 'ts',
"src": { core: 'ts'
"button": "ts",
"checkbox": "ts",
"input": "ts"
}
} }
}, },
"Downloads": { material2: {
"Tutorial": "html", src: {
"November": "pdf", button: 'ts',
"October": "pdf" checkbox: 'ts',
}, input: 'ts'
"Pictures": { }
"Sun": "png",
"Woods": "jpg",
"Photo Booth Library": {
"Contents": "dir",
"Pictures": "dir"
}
},
"Applications": {
"Chrome": "app",
"Calendar": "app",
"Webstorm": "app"
} }
}`; },
Downloads: {
October: 'pdf',
November: 'pdf',
Tutorial: 'html'
},
Pictures: {
'Photo Booth Library': {
Contents: 'dir',
Pictures: 'dir'
},
Sun: 'png',
Woods: 'jpg'
}
});
/** /**
* File database, it can build a tree structured Json object from string. * File database, it can build a tree structured Json object from string.
@ -70,7 +67,7 @@ const TREE_DATA = `
*/ */
@Injectable() @Injectable()
export class FileDatabase { export class FileDatabase {
dataChange: BehaviorSubject<FileNode[]> = new BehaviorSubject<FileNode[]>([]); dataChange = new BehaviorSubject<FileNode[]>([]);
get data(): FileNode[] { return this.dataChange.value; } get data(): FileNode[] { return this.dataChange.value; }
@ -94,22 +91,22 @@ export class FileDatabase {
* Build the file structure tree. The `value` is the Json object, or a sub-tree of a Json object. * Build the file structure tree. The `value` is the Json object, or a sub-tree of a Json object.
* The return value is the list of `FileNode`. * The return value is the list of `FileNode`.
*/ */
buildFileTree(value: any, level: number): FileNode[] { buildFileTree(obj: object, level: number): FileNode[] {
let data: any[] = []; return Object.keys(obj).reduce<FileNode[]>((accumulator, key) => {
for (let k in value) { const value = obj[key];
let v = value[k]; const node = new FileNode();
let node = new FileNode(); node.filename = key;
node.filename = `${k}`;
if (v === null || v === undefined) { if (value != null) {
// no action if (typeof value === 'object') {
} else if (typeof v === 'object') { node.children = this.buildFileTree(value, level + 1);
node.children = this.buildFileTree(v, level + 1); } else {
} else { node.type = value;
node.type = v; }
} }
data.push(node);
} return accumulator.concat(node);
return data; }, []);
} }
} }
@ -123,11 +120,8 @@ export class FileDatabase {
providers: [FileDatabase] providers: [FileDatabase]
}) })
export class CdkTreeFlatExample { export class CdkTreeFlatExample {
treeControl: FlatTreeControl<FileFlatNode>; treeControl: FlatTreeControl<FileFlatNode>;
treeFlattener: MatTreeFlattener<FileNode, FileFlatNode>; treeFlattener: MatTreeFlattener<FileNode, FileFlatNode>;
dataSource: MatTreeFlatDataSource<FileNode, FileFlatNode>; dataSource: MatTreeFlatDataSource<FileNode, FileFlatNode>;
constructor(database: FileDatabase) { constructor(database: FileDatabase) {
@ -141,22 +135,15 @@ export class CdkTreeFlatExample {
}); });
} }
hasChild = (_: number, _nodeData: FileFlatNode) => _nodeData.expandable;
transformer = (node: FileNode, level: number) => { transformer = (node: FileNode, level: number) => {
let flatNode = new FileFlatNode(); return new FileFlatNode(!!node.children, node.filename, level, node.type);
flatNode.filename = node.filename;
flatNode.type = node.type;
flatNode.level = level;
flatNode.expandable = !!node.children;
return flatNode;
} }
private _getLevel = (node: FileFlatNode) => { return node.level; }; private _getLevel = (node: FileFlatNode) => node.level;
private _isExpandable = (node: FileFlatNode) => { return node.expandable; }; private _isExpandable = (node: FileFlatNode) => node.expandable;
private _getChildren = (node: FileNode): Observable<FileNode[]> => { private _getChildren = (node: FileNode): Observable<FileNode[]> => observableOf(node.children);
return observableOf(node.children);
}
hasChild = (_: number, _nodeData: FileFlatNode) => { return _nodeData.expandable; };
} }

View File

@ -15,42 +15,41 @@ export class FileNode {
/** /**
* The Json tree data in string. The data could be parsed into Json object * The Json tree data in string. The data could be parsed into Json object
*/ */
const TREE_DATA = ` const TREE_DATA = JSON.stringify({
{ Applications: {
"Documents": { Calendar: 'app',
"angular": { Chrome: 'app',
"src": { Webstorm: 'app'
"core": "ts", },
"compiler": "ts" Documents: {
} angular: {
}, src: {
"material2": { compiler: 'ts',
"src": { core: 'ts'
"button": "ts",
"checkbox": "ts",
"input": "ts"
}
} }
}, },
"Downloads": { material2: {
"Tutorial": "html", src: {
"November": "pdf", button: 'ts',
"October": "pdf" checkbox: 'ts',
}, input: 'ts'
"Pictures": { }
"Sun": "png",
"Woods": "jpg",
"Photo Booth Library": {
"Contents": "dir",
"Pictures": "dir"
}
},
"Applications": {
"Chrome": "app",
"Calendar": "app",
"Webstorm": "app"
} }
}`; },
Downloads: {
October: 'pdf',
November: 'pdf',
Tutorial: 'html'
},
Pictures: {
'Photo Booth Library': {
Contents: 'dir',
Pictures: 'dir'
},
Sun: 'png',
Woods: 'jpg'
}
});
/** /**
* File database, it can build a tree structured Json object from string. * File database, it can build a tree structured Json object from string.
@ -61,7 +60,7 @@ const TREE_DATA = `
*/ */
@Injectable() @Injectable()
export class FileDatabase { export class FileDatabase {
dataChange: BehaviorSubject<FileNode[]> = new BehaviorSubject<FileNode[]>([]); dataChange = new BehaviorSubject<FileNode[]>([]);
get data(): FileNode[] { return this.dataChange.value; } get data(): FileNode[] { return this.dataChange.value; }
@ -85,22 +84,22 @@ export class FileDatabase {
* Build the file structure tree. The `value` is the Json object, or a sub-tree of a Json object. * Build the file structure tree. The `value` is the Json object, or a sub-tree of a Json object.
* The return value is the list of `FileNode`. * The return value is the list of `FileNode`.
*/ */
buildFileTree(value: any, level: number): FileNode[] { buildFileTree(obj: object, level: number): FileNode[] {
let data: any[] = []; return Object.keys(obj).reduce<FileNode[]>((accumulator, key) => {
for (let k in value) { const value = obj[key];
let v = value[k]; const node = new FileNode();
let node = new FileNode(); node.filename = key;
node.filename = `${k}`;
if (v === null || v === undefined) { if (value != null) {
// no action if (typeof value === 'object') {
} else if (typeof v === 'object') { node.children = this.buildFileTree(value, level + 1);
node.children = this.buildFileTree(v, level + 1); } else {
} else { node.type = value;
node.type = v; }
} }
data.push(node);
} return accumulator.concat(node);
return data; }, []);
} }
} }
@ -115,7 +114,6 @@ export class FileDatabase {
}) })
export class CdkTreeNestedExample { export class CdkTreeNestedExample {
nestedTreeControl: NestedTreeControl<FileNode>; nestedTreeControl: NestedTreeControl<FileNode>;
nestedDataSource: MatTreeNestedDataSource<FileNode>; nestedDataSource: MatTreeNestedDataSource<FileNode>;
constructor(database: FileDatabase) { constructor(database: FileDatabase) {
@ -125,7 +123,7 @@ export class CdkTreeNestedExample {
database.dataChange.subscribe(data => this.nestedDataSource.data = data); database.dataChange.subscribe(data => this.nestedDataSource.data = data);
} }
private _getChildren = (node: FileNode) => { return observableOf(node.children); }; hasNestedChild = (_: number, nodeData: FileNode) => !nodeData.type;
hasNestedChild = (_: number, nodeData: FileNode) => {return !(nodeData.type); }; private _getChildren = (node: FileNode) => observableOf(node.children);
} }

View File

@ -1,3 +1,3 @@
.demo-chip-list { .example-chip-list {
width: 100%; width: 100%;
} }

View File

@ -1,4 +1,4 @@
<mat-form-field class="demo-chip-list"> <mat-form-field class="example-chip-list">
<mat-chip-list #chipList> <mat-chip-list #chipList>
<mat-chip <mat-chip
*ngFor="let fruit of fruits" *ngFor="let fruit of fruits"
@ -16,12 +16,11 @@
[matChipInputFor]="chipList" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur" [matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)" (matChipInputTokenEnd)="add($event)">
/>
</mat-chip-list> </mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)"> <mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit"> <mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
{{ fruit }} {{fruit}}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>

View File

@ -11,38 +11,25 @@ import {map, startWith} from 'rxjs/operators';
@Component({ @Component({
selector: 'chips-autocomplete-example', selector: 'chips-autocomplete-example',
templateUrl: 'chips-autocomplete-example.html', templateUrl: 'chips-autocomplete-example.html',
styleUrls: ['chips-autocomplete-example.css'] styleUrls: ['chips-autocomplete-example.css'],
}) })
export class ChipsAutocompleteExample { export class ChipsAutocompleteExample {
visible: boolean = true; visible = true;
selectable: boolean = true; selectable = true;
removable: boolean = true; removable = true;
addOnBlur: boolean = false; addOnBlur = false;
separatorKeysCodes: number[] = [ENTER, COMMA];
separatorKeysCodes = [ENTER, COMMA];
fruitCtrl = new FormControl(); fruitCtrl = new FormControl();
filteredFruits: Observable<string[]>;
filteredFruits: Observable<any[]>; fruits: string[] = ['Lemon'];
allFruits: string[] = ['Apple', 'Lemon', 'Lime', 'Orange', 'Strawberry'];
fruits = [
'Lemon',
];
allFruits = [
'Apple',
'Lemon',
'Lime',
'Orange',
'Strawberry'
];
@ViewChild('fruitInput') fruitInput: ElementRef; @ViewChild('fruitInput') fruitInput: ElementRef;
constructor() { constructor() {
this.filteredFruits = this.fruitCtrl.valueChanges.pipe( this.filteredFruits = this.fruitCtrl.valueChanges.pipe(
startWith(null), startWith(null),
map((fruit: string | null) => fruit ? this.filter(fruit) : this.allFruits.slice())); map((fruit: string | null) => fruit ? this._filter(fruit) : this.allFruits.slice()));
} }
add(event: MatChipInputEvent): void { add(event: MatChipInputEvent): void {
@ -62,7 +49,7 @@ export class ChipsAutocompleteExample {
this.fruitCtrl.setValue(null); this.fruitCtrl.setValue(null);
} }
remove(fruit: any): void { remove(fruit: string): void {
const index = this.fruits.indexOf(fruit); const index = this.fruits.indexOf(fruit);
if (index >= 0) { if (index >= 0) {
@ -70,14 +57,15 @@ export class ChipsAutocompleteExample {
} }
} }
filter(name: string) {
return this.allFruits.filter(fruit =>
fruit.toLowerCase().indexOf(name.toLowerCase()) === 0);
}
selected(event: MatAutocompleteSelectedEvent): void { selected(event: MatAutocompleteSelectedEvent): void {
this.fruits.push(event.option.viewValue); this.fruits.push(event.option.viewValue);
this.fruitInput.nativeElement.value = ''; this.fruitInput.nativeElement.value = '';
this.fruitCtrl.setValue(null); this.fruitCtrl.setValue(null);
} }
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.allFruits.filter(fruit => fruit.toLowerCase().indexOf(filterValue) === 0);
}
} }

View File

@ -1,3 +1,3 @@
.demo-chip-list { .example-chip-list {
width: 100%; width: 100%;
} }

View File

@ -1,4 +1,4 @@
<mat-form-field class="demo-chip-list"> <mat-form-field class="example-chip-list">
<mat-chip-list #chipList> <mat-chip-list #chipList>
<mat-chip *ngFor="let fruit of fruits" [selectable]="selectable" <mat-chip *ngFor="let fruit of fruits" [selectable]="selectable"
[removable]="removable" (removed)="remove(fruit)"> [removable]="removable" (removed)="remove(fruit)">
@ -9,6 +9,6 @@
[matChipInputFor]="chipList" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur" [matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)" /> (matChipInputTokenEnd)="add($event)">
</mat-chip-list> </mat-chip-list>
</mat-form-field> </mat-form-field>

View File

@ -1,6 +1,10 @@
import {COMMA, ENTER} from '@angular/cdk/keycodes';
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {MatChipInputEvent} from '@angular/material'; import {MatChipInputEvent} from '@angular/material';
import {ENTER, COMMA} from '@angular/cdk/keycodes';
export interface Fruit {
name: string;
}
/** /**
* @title Chips with input * @title Chips with input
@ -8,31 +12,27 @@ import {ENTER, COMMA} from '@angular/cdk/keycodes';
@Component({ @Component({
selector: 'chips-input-example', selector: 'chips-input-example',
templateUrl: 'chips-input-example.html', templateUrl: 'chips-input-example.html',
styleUrls: ['chips-input-example.css'] styleUrls: ['chips-input-example.css'],
}) })
export class ChipsInputExample { export class ChipsInputExample {
visible: boolean = true; visible = true;
selectable: boolean = true; selectable = true;
removable: boolean = true; removable = true;
addOnBlur: boolean = true; addOnBlur = true;
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
// Enter, comma fruits: Fruit[] = [
separatorKeysCodes = [ENTER, COMMA]; {name: 'Lemon'},
{name: 'Lime'},
fruits = [ {name: 'Apple'},
{ name: 'Lemon' },
{ name: 'Lime' },
{ name: 'Apple' },
]; ];
add(event: MatChipInputEvent): void { add(event: MatChipInputEvent): void {
let input = event.input; const input = event.input;
let value = event.value; const value = event.value;
// Add our fruit // Add our fruit
if ((value || '').trim()) { if ((value || '').trim()) {
this.fruits.push({ name: value.trim() }); this.fruits.push({name: value.trim()});
} }
// Reset the input value // Reset the input value
@ -41,8 +41,8 @@ export class ChipsInputExample {
} }
} }
remove(fruit: any): void { remove(fruit: Fruit): void {
let index = this.fruits.indexOf(fruit); const index = this.fruits.indexOf(fruit);
if (index >= 0) { if (index >= 0) {
this.fruits.splice(index, 1); this.fruits.splice(index, 1);

View File

@ -1,6 +1,6 @@
<mat-chip-list> <mat-chip-list>
<mat-chip>One fish</mat-chip> <mat-chip>One fish</mat-chip>
<mat-chip>Two fish</mat-chip> <mat-chip>Two fish</mat-chip>
<mat-chip color="primary" selected="true">Primary fish</mat-chip> <mat-chip color="primary" selected>Primary fish</mat-chip>
<mat-chip color="accent" selected="true">Accent fish</mat-chip> <mat-chip color="accent" selected>Accent fish</mat-chip>
</mat-chip-list> </mat-chip-list>

View File

@ -1,5 +1,5 @@
<mat-chip-list class="mat-chip-list-stacked"> <mat-chip-list class="mat-chip-list-stacked">
<mat-chip *ngFor="let chip of availableColors" selected="true" [color]="chip.color"> <mat-chip *ngFor="let chip of availableColors" selected [color]="chip.color">
{{chip.name}} {{chip.name}}
</mat-chip> </mat-chip>
</mat-chip-list> </mat-chip-list>

View File

@ -1,4 +1,10 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {ThemePalette} from '@angular/material/core';
export interface ChipColor {
name: string;
color: ThemePalette;
}
/** /**
* @title Stacked chips * @title Stacked chips
@ -9,12 +15,10 @@ import {Component} from '@angular/core';
styleUrls: ['chips-stacked-example.css'], styleUrls: ['chips-stacked-example.css'],
}) })
export class ChipsStackedExample { export class ChipsStackedExample {
color: string; availableColors: ChipColor[] = [
{name: 'none', color: undefined},
availableColors = [ {name: 'Primary', color: 'primary'},
{ name: 'none', color: '' }, {name: 'Accent', color: 'accent'},
{ name: 'Primary', color: 'primary' }, {name: 'Warn', color: 'warn'}
{ name: 'Accent', color: 'accent' },
{ name: 'Warn', color: 'warn' }
]; ];
} }

View File

@ -4,8 +4,7 @@ import {
Component, Component,
Host, Host,
Inject, Inject,
OnDestroy, OnDestroy
ViewEncapsulation
} from '@angular/core'; } from '@angular/core';
import {MatCalendar} from '@angular/material'; import {MatCalendar} from '@angular/material';
import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core'; import {DateAdapter, MAT_DATE_FORMATS, MatDateFormats} from '@angular/material/core';
@ -17,7 +16,6 @@ import {takeUntil} from 'rxjs/operators';
selector: 'datepicker-custom-header-example', selector: 'datepicker-custom-header-example',
templateUrl: 'datepicker-custom-header-example.html', templateUrl: 'datepicker-custom-header-example.html',
styleUrls: ['datepicker-custom-header-example.css'], styleUrls: ['datepicker-custom-header-example.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class DatepickerCustomHeaderExample { export class DatepickerCustomHeaderExample {
@ -46,7 +44,6 @@ export class DatepickerCustomHeaderExample {
</button> </button>
</div> </div>
`, `,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class ExampleHeader<D> implements OnDestroy { export class ExampleHeader<D> implements OnDestroy {
@ -73,13 +70,13 @@ export class ExampleHeader<D> implements OnDestroy {
} }
previousClicked(mode: 'month' | 'year') { previousClicked(mode: 'month' | 'year') {
this.calendar.activeDate = mode == 'month' ? this.calendar.activeDate = mode === 'month' ?
this.dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) : this.dateAdapter.addCalendarMonths(this.calendar.activeDate, -1) :
this.dateAdapter.addCalendarYears(this.calendar.activeDate, -1); this.dateAdapter.addCalendarYears(this.calendar.activeDate, -1);
} }
nextClicked(mode: 'month' | 'year') { nextClicked(mode: 'month' | 'year') {
this.calendar.activeDate = mode == 'month' ? this.calendar.activeDate = mode === 'month' ?
this.dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) : this.dateAdapter.addCalendarMonths(this.calendar.activeDate, 1) :
this.dateAdapter.addCalendarYears(this.calendar.activeDate, 1); this.dateAdapter.addCalendarYears(this.calendar.activeDate, 1);
} }

View File

@ -1,5 +1,5 @@
<mat-form-field class="example-full-width"> <mat-form-field class="example-full-width">
<input matInput [matDatepicker]="picker" placeholder="Choose a date"> <input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle> <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker touchUi="true" #picker></mat-datepicker> <mat-datepicker touchUi #picker></mat-datepicker>
</mat-form-field> </mat-form-field>

View File

@ -1,4 +1,4 @@
import {Component, ViewEncapsulation} from '@angular/core'; import {Component} from '@angular/core';
import {FormControl} from '@angular/forms'; import {FormControl} from '@angular/forms';
import {MomentDateAdapter} from '@angular/material-moment-adapter'; import {MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core'; import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
@ -35,7 +35,6 @@ export const MY_FORMATS = {
selector: 'datepicker-views-selection-example', selector: 'datepicker-views-selection-example',
templateUrl: 'datepicker-views-selection-example.html', templateUrl: 'datepicker-views-selection-example.html',
styleUrls: ['datepicker-views-selection-example.css'], styleUrls: ['datepicker-views-selection-example.css'],
encapsulation: ViewEncapsulation.None,
providers: [ providers: [
// `MomentDateAdapter` can be automatically provided by importing `MomentDateModule` in your // `MomentDateAdapter` can be automatically provided by importing `MomentDateModule` in your
// application's root module. We provide it at the component level here, due to limitations of // application's root module. We provide it at the component level here, due to limitations of

View File

@ -1,25 +1,64 @@
<h2 mat-dialog-title>Install Angular</h2> <h2 mat-dialog-title>Install Angular</h2>
<mat-dialog-content> <mat-dialog-content class="mat-typography">
<h3>DEVELOP ACROSS ALL PLATFORMS</h3> <h3>Develop across all platforms</h3>
<p>Learn one way to build applications with Angular and reuse your code and abilities to build <p>Learn one way to build applications with Angular and reuse your code and abilities to build
apps for any deployment target. For web, mobile web, native mobile and native desktop.</p> apps for any deployment target. For web, mobile web, native mobile and native desktop.</p>
<h3>SPEED &amp; PERFORMANCE</h3> <h3>Speed &amp; Performance</h3>
<p>Achieve the maximum speed possible on the Web Platform today, and take it further, via Web <p>Achieve the maximum speed possible on the Web Platform today, and take it further, via Web
Workers and server-side rendering. Angular puts you in control over scalability. Meet huge data requirements Workers and server-side rendering. Angular puts you in control over scalability. Meet huge
by building data models on RxJS, Immutable.js or another push-model.</p> data requirements by building data models on RxJS, Immutable.js or another push-model.</p>
<h3>INCREDIBLE TOOLING</h3> <h3>Incredible tooling</h3>
<p>Build features quickly with simple, declarative templates. Extend the template language with your own <p>Build features quickly with simple, declarative templates. Extend the template language with
components and use a wide array of existing components. Get immediate Angular-specific help and feedback your own components and use a wide array of existing components. Get immediate Angular-specific
with nearly every IDE and editor. All this comes together so you can focus on building amazing apps rather help and feedback with nearly every IDE and editor. All this comes together so you can focus
than trying to make the code work.</p> on building amazing apps rather than trying to make the code work.</p>
<h3>LOVED BY MILLIONS</h3> <h3>Loved by millions</h3>
<p>From prototype through global deployment, Angular delivers the productivity and scalable infrastructure <p>From prototype through global deployment, Angular delivers the productivity and scalable
that supports Google's largest applications.</p> infrastructure that supports Google's largest applications.</p>
<h3>What is Angular?</h3>
<p>Angular is a platform that makes it easy to build applications with the web. Angular
combines declarative templates, dependency injection, end to end tooling, and integrated
best practices to solve development challenges. Angular empowers developers to build
applications that live on the web, mobile, or the desktop</p>
<h3>Architecture overview</h3>
<p>Angular is a platform and framework for building client applications in HTML and TypeScript.
Angular is itself written in TypeScript. It implements core and optional functionality as a
set of TypeScript libraries that you import into your apps.</p>
<p>The basic building blocks of an Angular application are NgModules, which provide a compilation
context for components. NgModules collect related code into functional sets; an Angular app is
defined by a set of NgModules. An app always has at least a root module that enables
bootstrapping, and typically has many more feature modules.</p>
<p>Components define views, which are sets of screen elements that Angular can choose among and
modify according to your program logic and data. Every app has at least a root component.</p>
<p>Components use services, which provide specific functionality not directly related to views.
Service providers can be injected into components as dependencies, making your code modular,
reusable, and efficient.</p>
<p>Both components and services are simply classes, with decorators that mark their type and
provide metadata that tells Angular how to use them.</p>
<p>The metadata for a component class associates it with a template that defines a view. A
template combines ordinary HTML with Angular directives and binding markup that allow Angular
to modify the HTML before rendering it for display.</p>
<p>The metadata for a service class provides the information Angular needs to make it available
to components through Dependency Injection (DI).</p>
<p>An app's components typically define many views, arranged hierarchically. Angular provides
the Router service to help you define navigation paths among views. The router provides
sophisticated in-browser navigational capabilities.</p>
</mat-dialog-content> </mat-dialog-content>
<mat-dialog-actions> <mat-dialog-actions align="end">
<button mat-button mat-dialog-close>Cancel</button> <button mat-button mat-dialog-close>Cancel</button>
<button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install</button> <button mat-button [mat-dialog-close]="true" cdkFocusInitial>Install</button>
</mat-dialog-actions> </mat-dialog-actions>

View File

@ -13,9 +13,7 @@ export class DialogContentExample {
constructor(public dialog: MatDialog) {} constructor(public dialog: MatDialog) {}
openDialog() { openDialog() {
const dialogRef = this.dialog.open(DialogContentExampleDialog, { const dialogRef = this.dialog.open(DialogContentExampleDialog);
height: '350px'
});
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`); console.log(`Dialog result: ${result}`);

View File

@ -1,13 +1,17 @@
import {Component, Inject} from '@angular/core'; import {Component, Inject} from '@angular/core';
import {MatDialog, MAT_DIALOG_DATA} from '@angular/material'; import {MatDialog, MAT_DIALOG_DATA} from '@angular/material';
export interface DialogData {
animal: 'panda' | 'unicorn' | 'lion';
}
/** /**
* @title Injecting data when opening a dialog * @title Injecting data when opening a dialog
*/ */
@Component({ @Component({
selector: 'dialog-data-example', selector: 'dialog-data-example',
templateUrl: 'dialog-data-example.html', templateUrl: 'dialog-data-example.html',
styleUrls: ['dialog-data-example.css'] styleUrls: ['dialog-data-example.css'],
}) })
export class DialogDataExample { export class DialogDataExample {
constructor(public dialog: MatDialog) {} constructor(public dialog: MatDialog) {}
@ -26,5 +30,5 @@ export class DialogDataExample {
templateUrl: 'dialog-data-example-dialog.html', templateUrl: 'dialog-data-example-dialog.html',
}) })
export class DialogDataExampleDialog { export class DialogDataExampleDialog {
constructor(@Inject(MAT_DIALOG_DATA) public data: any) {} constructor(@Inject(MAT_DIALOG_DATA) public data: DialogData) {}
} }

View File

@ -10,7 +10,7 @@ import {MatDialog} from '@angular/material';
styleUrls: ['dialog-elements-example.css'], styleUrls: ['dialog-elements-example.css'],
}) })
export class DialogElementsExample { export class DialogElementsExample {
constructor(public dialog: MatDialog) { } constructor(public dialog: MatDialog) {}
openDialog() { openDialog() {
this.dialog.open(DialogElementsExampleDialog); this.dialog.open(DialogElementsExampleDialog);
@ -22,4 +22,4 @@ export class DialogElementsExample {
selector: 'dialog-elements-example-dialog', selector: 'dialog-elements-example-dialog',
templateUrl: 'dialog-elements-example-dialog.html', templateUrl: 'dialog-elements-example-dialog.html',
}) })
export class DialogElementsExampleDialog { } export class DialogElementsExampleDialog {}

View File

@ -1,6 +1,11 @@
import {Component, Inject} from '@angular/core'; import {Component, Inject} from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material'; import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export interface DialogData {
animal: string;
name: string;
}
/** /**
* @title Dialog Overview * @title Dialog Overview
*/ */
@ -17,9 +22,9 @@ export class DialogOverviewExample {
constructor(public dialog: MatDialog) {} constructor(public dialog: MatDialog) {}
openDialog(): void { openDialog(): void {
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, { const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px', width: '250px',
data: { name: this.name, animal: this.animal } data: {name: this.name, animal: this.animal}
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
@ -38,7 +43,7 @@ export class DialogOverviewExampleDialog {
constructor( constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>, public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { } @Inject(MAT_DIALOG_DATA) public data: DialogData) {}
onNoClick(): void { onNoClick(): void {
this.dialogRef.close(); this.dialogRef.close();

View File

@ -1,60 +1,59 @@
<div class="example-action-buttons"> <div class="example-action-buttons">
<button mat-button (click)="accordion.openAll()">Expand All</button> <button mat-button (click)="accordion.openAll()">Expand All</button>
<button mat-button (click)="accordion.closeAll()">Collapse All</button> <button mat-button (click)="accordion.closeAll()">Collapse All</button>
</div> </div>
<mat-accordion class="example-headers-align" [multi]="true"> <mat-accordion class="example-headers-align" multi>
<mat-expansion-panel> <mat-expansion-panel>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Personal data Personal data
</mat-panel-title> </mat-panel-title>
<mat-panel-description> <mat-panel-description>
Type your name and age Type your name and age
<mat-icon>account_circle</mat-icon> <mat-icon>account_circle</mat-icon>
</mat-panel-description> </mat-panel-description>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<mat-form-field> <mat-form-field>
<input matInput placeholder="First name"> <input matInput placeholder="First name">
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field>
<input matInput type="number" min="1" placeholder="Age"> <input matInput type="number" min="1" placeholder="Age">
</mat-form-field> </mat-form-field>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel [disabled]="true"> <mat-expansion-panel disabled>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Destination Destination
</mat-panel-title> </mat-panel-title>
<mat-panel-description> <mat-panel-description>
Type the country name Type the country name
<mat-icon>map</mat-icon> <mat-icon>map</mat-icon>
</mat-panel-description> </mat-panel-description>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<mat-form-field> <mat-form-field>
<input matInput placeholder="Country"> <input matInput placeholder="Country">
</mat-form-field> </mat-form-field>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel> <mat-expansion-panel>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Day of the trip Day of the trip
</mat-panel-title> </mat-panel-title>
<mat-panel-description> <mat-panel-description>
Inform the date you wish to travel Inform the date you wish to travel
<mat-icon>date_range</mat-icon> <mat-icon>date_range</mat-icon>
</mat-panel-description> </mat-panel-description>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<mat-form-field>
<input matInput placeholder="Date" [matDatepicker]="picker" (focus)="picker.open()" readonly>
</mat-form-field>
<mat-datepicker #picker></mat-datepicker>
</mat-expansion-panel>
<mat-form-field>
<input matInput placeholder="Date" [matDatepicker]="picker" (focus)="picker.open()" readonly>
</mat-form-field>
<mat-datepicker #picker></mat-datepicker>
</mat-expansion-panel>
</mat-accordion> </mat-accordion>

View File

@ -7,7 +7,7 @@ import {MatAccordion} from '@angular/material';
@Component({ @Component({
selector: 'expansion-toggle-all-example', selector: 'expansion-toggle-all-example',
templateUrl: 'expansion-expand-collapse-all-example.html', templateUrl: 'expansion-expand-collapse-all-example.html',
styleUrls: ['expansion-expand-collapse-all-example.css'] styleUrls: ['expansion-expand-collapse-all-example.css'],
}) })
export class ExpansionExpandCollapseAllExample { export class ExpansionExpandCollapseAllExample {
@ViewChild(MatAccordion) accordion: MatAccordion; @ViewChild(MatAccordion) accordion: MatAccordion;

View File

@ -9,5 +9,5 @@ import {Component} from '@angular/core';
styleUrls: ['expansion-overview-example.css'], styleUrls: ['expansion-overview-example.css'],
}) })
export class ExpansionOverviewExample { export class ExpansionOverviewExample {
panelOpenState: boolean = false; panelOpenState = false;
} }

View File

@ -1,5 +1,5 @@
<mat-accordion class="example-headers-align"> <mat-accordion class="example-headers-align">
<mat-expansion-panel [expanded]="step === 0" (opened)="setStep(0)" hideToggle="true"> <mat-expansion-panel [expanded]="step === 0" (opened)="setStep(0)" hideToggle>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Personal data Personal data
@ -23,7 +23,7 @@
</mat-action-row> </mat-action-row>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel [expanded]="step === 1" (opened)="setStep(1)" hideToggle="true"> <mat-expansion-panel [expanded]="step === 1" (opened)="setStep(1)" hideToggle>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Destination Destination
@ -44,7 +44,7 @@
</mat-action-row> </mat-action-row>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel [expanded]="step === 2" (opened)="setStep(2)" hideToggle="true"> <mat-expansion-panel [expanded]="step === 2" (opened)="setStep(2)" hideToggle>
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title> <mat-panel-title>
Day of the trip Day of the trip

View File

@ -6,7 +6,7 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'expansion-steps-example', selector: 'expansion-steps-example',
templateUrl: 'expansion-steps-example.html', templateUrl: 'expansion-steps-example.html',
styleUrls: ['expansion-steps-example.css'] styleUrls: ['expansion-steps-example.css'],
}) })
export class ExpansionStepsExample { export class ExpansionStepsExample {
step = 0; step = 0;

View File

@ -8,8 +8,8 @@ import {ChangeDetectorRef, Component, NgZone} from '@angular/core';
styleUrls: ['focus-monitor-directives-example.css'] styleUrls: ['focus-monitor-directives-example.css']
}) })
export class FocusMonitorDirectivesExample { export class FocusMonitorDirectivesExample {
elementOrigin: string = this.formatOrigin(null); elementOrigin = this.formatOrigin(null);
subtreeOrigin: string = this.formatOrigin(null); subtreeOrigin = this.formatOrigin(null);
constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef) {} constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef) {}

View File

@ -18,7 +18,7 @@ import {
export class FocusMonitorFocusViaExample implements OnDestroy, OnInit { export class FocusMonitorFocusViaExample implements OnDestroy, OnInit {
@ViewChild('monitored') monitoredEl: ElementRef; @ViewChild('monitored') monitoredEl: ElementRef;
origin: string = this.formatOrigin(null); origin = this.formatOrigin(null);
constructor(public focusMonitor: FocusMonitor, constructor(public focusMonitor: FocusMonitor,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,

View File

@ -19,8 +19,8 @@ export class FocusMonitorOverviewExample implements OnDestroy, OnInit {
@ViewChild('element') element: ElementRef; @ViewChild('element') element: ElementRef;
@ViewChild('subtree') subtree: ElementRef; @ViewChild('subtree') subtree: ElementRef;
elementOrigin: string = this.formatOrigin(null); elementOrigin = this.formatOrigin(null);
subtreeOrigin: string = this.formatOrigin(null); subtreeOrigin = this.formatOrigin(null);
constructor(private focusMonitor: FocusMonitor, constructor(private focusMonitor: FocusMonitor,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,

View File

@ -4,6 +4,6 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'form-field-appearance-example', selector: 'form-field-appearance-example',
templateUrl: 'form-field-appearance-example.html', templateUrl: 'form-field-appearance-example.html',
styleUrls: ['form-field-appearance-example.css'] styleUrls: ['form-field-appearance-example.css'],
}) })
export class FormFieldAppearanceExample {} export class FormFieldAppearanceExample {}

View File

@ -5,7 +5,6 @@ import {FormBuilder, FormGroup} from '@angular/forms';
import {MatFormFieldControl} from '@angular/material'; import {MatFormFieldControl} from '@angular/material';
import {Subject} from 'rxjs'; import {Subject} from 'rxjs';
/** Data structure for holding telephone number. */ /** Data structure for holding telephone number. */
export class MyTel { export class MyTel {
constructor(public area: string, public exchange: string, public subscriber: string) {} constructor(public area: string, public exchange: string, public subscriber: string) {}
@ -28,74 +27,68 @@ export class MyTelInput implements MatFormFieldControl<MyTel>, OnDestroy {
static nextId = 0; static nextId = 0;
parts: FormGroup; parts: FormGroup;
stateChanges = new Subject<void>(); stateChanges = new Subject<void>();
focused = false; focused = false;
ngControl = null; ngControl = null;
errorState = false; errorState = false;
controlType = 'my-tel-input'; controlType = 'my-tel-input';
id = `my-tel-input-${MyTelInput.nextId++}`;
describedBy = '';
get empty() { get empty() {
let n = this.parts.value; const {value: {area, exchange, subscriber}} = this.parts;
return !n.area && !n.exchange && !n.subscriber;
return !area && !exchange && !subscriber;
} }
get shouldLabelFloat() { return this.focused || !this.empty; } get shouldLabelFloat() { return this.focused || !this.empty; }
id = `my-tel-input-${MyTelInput.nextId++}`;
describedBy = '';
@Input() @Input()
get placeholder() { return this._placeholder; } get placeholder(): string { return this._placeholder; }
set placeholder(plh) { set placeholder(value: string) {
this._placeholder = plh; this._placeholder = value;
this.stateChanges.next(); this.stateChanges.next();
} }
private _placeholder: string; private _placeholder: string;
@Input() @Input()
get required() { return this._required; } get required(): boolean { return this._required; }
set required(req) { set required(value: boolean) {
this._required = coerceBooleanProperty(req); this._required = coerceBooleanProperty(value);
this.stateChanges.next(); this.stateChanges.next();
} }
private _required = false; private _required = false;
@Input() @Input()
get disabled() { return this._disabled; } get disabled(): boolean { return this._disabled; }
set disabled(dis) { set disabled(value: boolean) {
this._disabled = coerceBooleanProperty(dis); this._disabled = coerceBooleanProperty(value);
this.stateChanges.next(); this.stateChanges.next();
} }
private _disabled = false; private _disabled = false;
@Input() @Input()
get value(): MyTel | null { get value(): MyTel | null {
let n = this.parts.value; const {value: {area, exchange, subscriber}} = this.parts;
if (n.area.length == 3 && n.exchange.length == 3 && n.subscriber.length == 4) { if (area.length === 3 && exchange.length === 3 && subscriber.length === 4) {
return new MyTel(n.area, n.exchange, n.subscriber); return new MyTel(area, exchange, subscriber);
} }
return null; return null;
} }
set value(tel: MyTel | null) { set value(tel: MyTel | null) {
tel = tel || new MyTel('', '', ''); const {area, exchange, subscriber} = tel || new MyTel('', '', '');
this.parts.setValue({area: tel.area, exchange: tel.exchange, subscriber: tel.subscriber}); this.parts.setValue({area, exchange, subscriber});
this.stateChanges.next(); this.stateChanges.next();
} }
constructor(fb: FormBuilder, private fm: FocusMonitor, private elRef: ElementRef) { constructor(fb: FormBuilder, private fm: FocusMonitor, private elRef: ElementRef) {
this.parts = fb.group({ this.parts = fb.group({
'area': '', area: '',
'exchange': '', exchange: '',
'subscriber': '', subscriber: '',
}); });
fm.monitor(elRef.nativeElement, true).subscribe((origin) => { fm.monitor(elRef.nativeElement, true).subscribe(origin => {
this.focused = !!origin; this.focused = !!origin;
this.stateChanges.next(); this.stateChanges.next();
}); });

View File

@ -5,7 +5,7 @@ import {FormControl, Validators} from '@angular/forms';
@Component({ @Component({
selector: 'form-field-error-example', selector: 'form-field-error-example',
templateUrl: 'form-field-error-example.html', templateUrl: 'form-field-error-example.html',
styleUrls: ['form-field-error-example.css'] styleUrls: ['form-field-error-example.css'],
}) })
export class FormFieldErrorExample { export class FormFieldErrorExample {
email = new FormControl('', [Validators.required, Validators.email]); email = new FormControl('', [Validators.required, Validators.email]);

View File

@ -4,6 +4,6 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'form-field-hint-example', selector: 'form-field-hint-example',
templateUrl: 'form-field-hint-example.html', templateUrl: 'form-field-hint-example.html',
styleUrls: ['form-field-hint-example.css'] styleUrls: ['form-field-hint-example.css'],
}) })
export class FormFieldHintExample {} export class FormFieldHintExample {}

View File

@ -5,7 +5,7 @@ import {FormBuilder, FormGroup} from '@angular/forms';
@Component({ @Component({
selector: 'form-field-label-example', selector: 'form-field-label-example',
templateUrl: 'form-field-label-example.html', templateUrl: 'form-field-label-example.html',
styleUrls: ['form-field-label-example.css'] styleUrls: ['form-field-label-example.css'],
}) })
export class FormFieldLabelExample { export class FormFieldLabelExample {
options: FormGroup; options: FormGroup;

View File

@ -4,6 +4,6 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'form-field-overview-example', selector: 'form-field-overview-example',
templateUrl: 'form-field-overview-example.html', templateUrl: 'form-field-overview-example.html',
styleUrls: ['form-field-overview-example.css'] styleUrls: ['form-field-overview-example.css'],
}) })
export class FormFieldOverviewExample {} export class FormFieldOverviewExample {}

View File

@ -4,7 +4,7 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'form-field-prefix-suffix-example', selector: 'form-field-prefix-suffix-example',
templateUrl: 'form-field-prefix-suffix-example.html', templateUrl: 'form-field-prefix-suffix-example.html',
styleUrls: ['form-field-prefix-suffix-example.css'] styleUrls: ['form-field-prefix-suffix-example.css'],
}) })
export class FormFieldPrefixSuffixExample { export class FormFieldPrefixSuffixExample {
hide = true; hide = true;

View File

@ -5,15 +5,15 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({ @Component({
selector: 'form-field-theming-example', selector: 'form-field-theming-example',
templateUrl: 'form-field-theming-example.html', templateUrl: 'form-field-theming-example.html',
styleUrls: ['form-field-theming-example.css'] styleUrls: ['form-field-theming-example.css'],
}) })
export class FormFieldThemingExample { export class FormFieldThemingExample {
options: FormGroup; options: FormGroup;
constructor(fb: FormBuilder) { constructor(fb: FormBuilder) {
this.options = fb.group({ this.options = fb.group({
'color': 'primary', color: 'primary',
'fontSize': [16, Validators.min(10)], fontSize: [16, Validators.min(10)],
}); });
} }

View File

@ -1,5 +1,12 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
export interface Tile {
color: string;
cols: number;
rows: number;
text: string;
}
/** /**
* @title Dynamic grid-list * @title Dynamic grid-list
*/ */
@ -9,7 +16,7 @@ import {Component} from '@angular/core';
styleUrls: ['grid-list-dynamic-example.css'], styleUrls: ['grid-list-dynamic-example.css'],
}) })
export class GridListDynamicExample { export class GridListDynamicExample {
tiles = [ tiles: Tile[] = [
{text: 'One', cols: 3, rows: 1, color: 'lightblue'}, {text: 'One', cols: 3, rows: 1, color: 'lightblue'},
{text: 'Two', cols: 1, rows: 2, color: 'lightgreen'}, {text: 'Two', cols: 1, rows: 2, color: 'lightgreen'},
{text: 'Three', cols: 1, rows: 1, color: 'lightpink'}, {text: 'Three', cols: 1, rows: 1, color: 'lightpink'},

View File

@ -6,6 +6,6 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'icon-overview-example', selector: 'icon-overview-example',
templateUrl: 'icon-overview-example.html', templateUrl: 'icon-overview-example.html',
styleUrls: ['icon-overview-example.css'] styleUrls: ['icon-overview-example.css'],
}) })
export class IconOverviewExample {} export class IconOverviewExample {}

View File

@ -1,5 +1,5 @@
<mat-form-field class="example-form-field"> <mat-form-field class="example-form-field">
<input matInput type="text" placeholder="Clearable input" [(ngModel)]="value"/> <input matInput type="text" placeholder="Clearable input" [(ngModel)]="value">
<button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''"> <button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
<mat-icon>close</mat-icon> <mat-icon>close</mat-icon>
</button> </button>

View File

@ -1,5 +1,10 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
export interface Section {
name: string;
updated: Date;
}
/** /**
* @title List with sections * @title List with sections
*/ */
@ -9,7 +14,7 @@ import {Component} from '@angular/core';
templateUrl: 'list-sections-example.html', templateUrl: 'list-sections-example.html',
}) })
export class ListSectionsExample { export class ListSectionsExample {
folders = [ folders: Section[] = [
{ {
name: 'Photos', name: 'Photos',
updated: new Date('1/1/16'), updated: new Date('1/1/16'),
@ -23,7 +28,7 @@ export class ListSectionsExample {
updated: new Date('1/28/16'), updated: new Date('1/28/16'),
} }
]; ];
notes = [ notes: Section[] = [
{ {
name: 'Vacation Itinerary', name: 'Vacation Itinerary',
updated: new Date('2/20/16'), updated: new Date('2/20/16'),

View File

@ -9,5 +9,5 @@ import {Component} from '@angular/core';
templateUrl: 'list-selection-example.html', templateUrl: 'list-selection-example.html',
}) })
export class ListSelectionExample { export class ListSelectionExample {
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers']; typesOfShoes: string[] = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
} }

View File

@ -6,6 +6,6 @@ import {Component} from '@angular/core';
@Component({ @Component({
selector: 'nested-menu-example', selector: 'nested-menu-example',
templateUrl: 'nested-menu-example.html', templateUrl: 'nested-menu-example.html',
styleUrls: ['nested-menu-example.css'] styleUrls: ['nested-menu-example.css'],
}) })
export class NestedMenuExample {} export class NestedMenuExample {}

View File

@ -13,7 +13,7 @@ export class PaginatorConfigurableExample {
// MatPaginator Inputs // MatPaginator Inputs
length = 100; length = 100;
pageSize = 10; pageSize = 10;
pageSizeOptions = [5, 10, 25, 100]; pageSizeOptions: number[] = [5, 10, 25, 100];
// MatPaginator Output // MatPaginator Output
pageEvent: PageEvent; pageEvent: PageEvent;

View File

@ -35,11 +35,11 @@
</mat-radio-group> </mat-radio-group>
</section> </section>
<section class="example-section" *ngIf="mode == 'determinate' || mode == 'buffer'"> <section class="example-section" *ngIf="mode === 'determinate' || mode === 'buffer'">
<label class="example-margin">Progress:</label> <label class="example-margin">Progress:</label>
<mat-slider class="example-margin" [(ngModel)]="value"></mat-slider> <mat-slider class="example-margin" [(ngModel)]="value"></mat-slider>
</section> </section>
<section class="example-section" *ngIf="mode == 'buffer'"> <section class="example-section" *ngIf="mode === 'buffer'">
<label class="example-margin">Buffer:</label> <label class="example-margin">Buffer:</label>
<mat-slider class="example-margin" [(ngModel)]="bufferValue"></mat-slider> <mat-slider class="example-margin" [(ngModel)]="bufferValue"></mat-slider>
</section> </section>

View File

@ -29,7 +29,7 @@
</mat-radio-group> </mat-radio-group>
</section> </section>
<section class="example-section" *ngIf="mode == 'determinate'"> <section class="example-section" *ngIf="mode === 'determinate'">
<label class="example-margin">Progress:</label> <label class="example-margin">Progress:</label>
<mat-slider class="example-margin" [(ngModel)]="value"></mat-slider> <mat-slider class="example-margin" [(ngModel)]="value"></mat-slider>
</section> </section>

View File

@ -10,11 +10,5 @@ import {Component} from '@angular/core';
}) })
export class RadioNgModelExample { export class RadioNgModelExample {
favoriteSeason: string; favoriteSeason: string;
seasons: string[] = ['Winter', 'Spring', 'Summer', 'Autumn'];
seasons = [
'Winter',
'Spring',
'Summer',
'Autumn',
];
} }

View File

@ -3,7 +3,7 @@
<mat-select-trigger> <mat-select-trigger>
{{toppings.value ? toppings.value[0] : ''}} {{toppings.value ? toppings.value[0] : ''}}
<span *ngIf="toppings.value?.length > 1" class="example-additional-selection"> <span *ngIf="toppings.value?.length > 1" class="example-additional-selection">
(+{{toppings.value.length - 1}} others) (+{{toppings.value.length - 1}} {{toppings.value?.length === 2 ? 'other' : 'others'}})
</span> </span>
</mat-select-trigger> </mat-select-trigger>
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option> <mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>

View File

@ -10,5 +10,5 @@ import {FormControl} from '@angular/forms';
export class SelectCustomTriggerExample { export class SelectCustomTriggerExample {
toppings = new FormControl(); toppings = new FormControl();
toppingList = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato']; toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
} }

View File

@ -1,5 +1,10 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
export interface Food {
value: string;
viewValue: string;
}
/** /**
* @title Select in a form * @title Select in a form
*/ */
@ -11,7 +16,7 @@ import {Component} from '@angular/core';
export class SelectFormExample { export class SelectFormExample {
selectedValue: string; selectedValue: string;
foods = [ foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak'}, {value: 'steak-0', viewValue: 'Steak'},
{value: 'pizza-1', viewValue: 'Pizza'}, {value: 'pizza-1', viewValue: 'Pizza'},
{value: 'tacos-2', viewValue: 'Tacos'} {value: 'tacos-2', viewValue: 'Tacos'}

View File

@ -1,6 +1,11 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {FormControl, Validators} from '@angular/forms'; import {FormControl, Validators} from '@angular/forms';
export interface Animal {
name: string;
sound: string;
}
/** @title Select with form field features */ /** @title Select with form field features */
@Component({ @Component({
selector: 'select-hint-error-example', selector: 'select-hint-error-example',
@ -9,8 +14,7 @@ import {FormControl, Validators} from '@angular/forms';
}) })
export class SelectHintErrorExample { export class SelectHintErrorExample {
animalControl = new FormControl('', [Validators.required]); animalControl = new FormControl('', [Validators.required]);
animals: Animal[] = [
animals = [
{name: 'Dog', sound: 'Woof!'}, {name: 'Dog', sound: 'Woof!'},
{name: 'Cat', sound: 'Meow!'}, {name: 'Cat', sound: 'Meow!'},
{name: 'Cow', sound: 'Moo!'}, {name: 'Cow', sound: 'Moo!'},

View File

@ -9,6 +9,5 @@ import {FormControl} from '@angular/forms';
}) })
export class SelectMultipleExample { export class SelectMultipleExample {
toppings = new FormControl(); toppings = new FormControl();
toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
toppingList = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
} }

View File

@ -4,7 +4,7 @@
<mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name" <mat-optgroup *ngFor="let group of pokemonGroups" [label]="group.name"
[disabled]="group.disabled"> [disabled]="group.disabled">
<mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value"> <mat-option *ngFor="let pokemon of group.pokemon" [value]="pokemon.value">
{{ pokemon.viewValue }} {{pokemon.viewValue}}
</mat-option> </mat-option>
</mat-optgroup> </mat-optgroup>
</mat-select> </mat-select>

View File

@ -1,6 +1,17 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {FormControl} from '@angular/forms'; import {FormControl} from '@angular/forms';
export interface Pokemon {
value: string;
viewValue: string;
}
export interface PokemonGroup {
disabled?: boolean;
name: string;
pokemon: Pokemon[];
}
/** @title Select with option groups */ /** @title Select with option groups */
@Component({ @Component({
selector: 'select-optgroup-example', selector: 'select-optgroup-example',
@ -9,38 +20,37 @@ import {FormControl} from '@angular/forms';
}) })
export class SelectOptgroupExample { export class SelectOptgroupExample {
pokemonControl = new FormControl(); pokemonControl = new FormControl();
pokemonGroups: PokemonGroup[] = [
pokemonGroups = [
{ {
name: 'Grass', name: 'Grass',
pokemon: [ pokemon: [
{ value: 'bulbasaur-0', viewValue: 'Bulbasaur' }, {value: 'bulbasaur-0', viewValue: 'Bulbasaur'},
{ value: 'oddish-1', viewValue: 'Oddish' }, {value: 'oddish-1', viewValue: 'Oddish'},
{ value: 'bellsprout-2', viewValue: 'Bellsprout' } {value: 'bellsprout-2', viewValue: 'Bellsprout'}
] ]
}, },
{ {
name: 'Water', name: 'Water',
pokemon: [ pokemon: [
{ value: 'squirtle-3', viewValue: 'Squirtle' }, {value: 'squirtle-3', viewValue: 'Squirtle'},
{ value: 'psyduck-4', viewValue: 'Psyduck' }, {value: 'psyduck-4', viewValue: 'Psyduck'},
{ value: 'horsea-5', viewValue: 'Horsea' } {value: 'horsea-5', viewValue: 'Horsea'}
] ]
}, },
{ {
name: 'Fire', name: 'Fire',
disabled: true, disabled: true,
pokemon: [ pokemon: [
{ value: 'charmander-6', viewValue: 'Charmander' }, {value: 'charmander-6', viewValue: 'Charmander'},
{ value: 'vulpix-7', viewValue: 'Vulpix' }, {value: 'vulpix-7', viewValue: 'Vulpix'},
{ value: 'flareon-8', viewValue: 'Flareon' } {value: 'flareon-8', viewValue: 'Flareon'}
] ]
}, },
{ {
name: 'Psychic', name: 'Psychic',
pokemon: [ pokemon: [
{ value: 'mew-9', viewValue: 'Mew' }, {value: 'mew-9', viewValue: 'Mew'},
{ value: 'mewtwo-10', viewValue: 'Mewtwo' }, {value: 'mewtwo-10', viewValue: 'Mewtwo'},
] ]
} }
]; ];

View File

@ -1,7 +1,7 @@
<mat-form-field> <mat-form-field>
<mat-select placeholder="Favorite food"> <mat-select placeholder="Favorite food">
<mat-option *ngFor="let food of foods" [value]="food.value"> <mat-option *ngFor="let food of foods" [value]="food.value">
{{ food.viewValue }} {{food.viewValue}}
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

View File

@ -1,5 +1,10 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
export interface Food {
value: string;
viewValue: string;
}
/** /**
* @title Basic select * @title Basic select
*/ */
@ -9,7 +14,7 @@ import {Component} from '@angular/core';
styleUrls: ['select-overview-example.css'], styleUrls: ['select-overview-example.css'],
}) })
export class SelectOverviewExample { export class SelectOverviewExample {
foods = [ foods: Food[] = [
{value: 'steak-0', viewValue: 'Steak'}, {value: 'steak-0', viewValue: 'Steak'},
{value: 'pizza-1', viewValue: 'Pizza'}, {value: 'pizza-1', viewValue: 'Pizza'},
{value: 'tacos-2', viewValue: 'Tacos'} {value: 'tacos-2', viewValue: 'Tacos'}

View File

@ -8,6 +8,8 @@ import {FormControl} from '@angular/forms';
selector: 'select-panel-class-example', selector: 'select-panel-class-example',
templateUrl: 'select-panel-class-example.html', templateUrl: 'select-panel-class-example.html',
styleUrls: ['select-panel-class-example.css'], styleUrls: ['select-panel-class-example.css'],
// Encapsulation has to be disabled in order for the
// component style to apply to the select panel.
encapsulation: ViewEncapsulation.None, encapsulation: ViewEncapsulation.None,
}) })
export class SelectPanelClassExample { export class SelectPanelClassExample {

View File

@ -7,7 +7,7 @@ import {Component} from '@angular/core';
styleUrls: ['select-reset-example.css'], styleUrls: ['select-reset-example.css'],
}) })
export class SelectResetExample { export class SelectResetExample {
states = [ states: string[] = [
'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware',
'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky',
'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi',

View File

@ -1,4 +1,4 @@
<mat-drawer-container class="example-container"> <mat-drawer-container class="example-container">
<mat-drawer mode="side" opened="true">Drawer content</mat-drawer> <mat-drawer mode="side" opened>Drawer content</mat-drawer>
<mat-drawer-content>Main content</mat-drawer-content> <mat-drawer-content>Main content</mat-drawer-content>
</mat-drawer-container> </mat-drawer-container>

View File

@ -2,7 +2,7 @@
<mat-toolbar class="example-header">Header</mat-toolbar> <mat-toolbar class="example-header">Header</mat-toolbar>
<mat-sidenav-container class="example-container"> <mat-sidenav-container class="example-container">
<mat-sidenav #sidenav mode="side" opened="true" class="example-sidenav" <mat-sidenav #sidenav mode="side" opened class="example-sidenav"
[fixedInViewport]="options.value.fixed" [fixedTopGap]="options.value.top" [fixedInViewport]="options.value.fixed" [fixedTopGap]="options.value.top"
[fixedBottomGap]="options.value.bottom"> [fixedBottomGap]="options.value.bottom">
{{options.value.fixed ? 'Fixed' : 'Non-fixed'}} Sidenav {{options.value.fixed ? 'Fixed' : 'Non-fixed'}} Sidenav

View File

@ -12,9 +12,9 @@ export class SidenavFixedExample {
constructor(fb: FormBuilder) { constructor(fb: FormBuilder) {
this.options = fb.group({ this.options = fb.group({
'fixed': false, bottom: 0,
'top': 0, fixed: false,
'bottom': 0, top: 0
}); });
} }

View File

@ -9,6 +9,5 @@ import {FormControl} from '@angular/forms';
}) })
export class SidenavModeExample { export class SidenavModeExample {
mode = new FormControl('over'); mode = new FormControl('over');
shouldRun = [/(^|\.)plnkr\.co$/, /(^|\.)stackblitz\.io$/].some(h => h.test(window.location.host)); shouldRun = [/(^|\.)plnkr\.co$/, /(^|\.)stackblitz\.io$/].some(h => h.test(window.location.host));
} }

View File

@ -10,9 +10,9 @@ import {ChangeDetectorRef, Component, OnDestroy} from '@angular/core';
export class SidenavResponsiveExample implements OnDestroy { export class SidenavResponsiveExample implements OnDestroy {
mobileQuery: MediaQueryList; mobileQuery: MediaQueryList;
fillerNav = Array(50).fill(0).map((_, i) => `Nav Item ${i + 1}`); fillerNav = Array.from({length: 50}, (_, i) => `Nav Item ${i + 1}`);
fillerContent = Array(50).fill(0).map(() => fillerContent = Array.from({length: 50}, () =>
`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in

View File

@ -1,10 +1,10 @@
<p>Slide Toggle using a simple NgModel.</p> <p>Slide Toggle using a simple NgModel.</p>
<mat-slide-toggle [(ngModel)]="isChecked">Slide Toggle Checked: {{ isChecked }}</mat-slide-toggle> <mat-slide-toggle [(ngModel)]="isChecked">Slide Toggle Checked: {{isChecked}}</mat-slide-toggle>
<p>Slide Toggle inside of a Template-driven form</p> <p>Slide Toggle inside of a Template-driven form</p>
<form class="example-form" #form="ngForm" (ngSubmit)="onFormSubmit(form.value)" ngNativeValidate> <form class="example-form" #form="ngForm" (ngSubmit)="onFormSubmit()" ngNativeValidate>
<mat-slide-toggle ngModel name="enableWifi">Enable Wifi</mat-slide-toggle> <mat-slide-toggle ngModel name="enableWifi">Enable Wifi</mat-slide-toggle>
<mat-slide-toggle ngModel name="acceptTerms" required>Accept Terms of Service</mat-slide-toggle> <mat-slide-toggle ngModel name="acceptTerms" required>Accept Terms of Service</mat-slide-toggle>
@ -14,12 +14,12 @@
<p>Slide Toggle inside of a Reactive form</p> <p>Slide Toggle inside of a Reactive form</p>
<form class="example-form" [formGroup]="formGroup" (ngSubmit)="onFormSubmit(formGroup.value)" ngNativeValidate> <form class="example-form" [formGroup]="formGroup" (ngSubmit)="onFormSubmit()" ngNativeValidate>
<mat-slide-toggle formControlName="enableWifi">Enable Wifi</mat-slide-toggle> <mat-slide-toggle formControlName="enableWifi">Enable Wifi</mat-slide-toggle>
<mat-slide-toggle formControlName="acceptTerms">Accept Terms of Service</mat-slide-toggle> <mat-slide-toggle formControlName="acceptTerms">Accept Terms of Service</mat-slide-toggle>
<p>Form Group Status: {{ formGroup.status}}</p> <p>Form Group Status: {{formGroup.status}}</p>
<button mat-rasied-button type="submit">Save Settings</button> <button mat-rasied-button type="submit">Save Settings</button>
</form> </form>

View File

@ -20,7 +20,7 @@ export class SlideToggleFormsExample {
}); });
} }
onFormSubmit(formValue: any) { onFormSubmit() {
alert(JSON.stringify(formValue, null, 2)); alert(JSON.stringify(this.formGroup.value, null, 2));
} }
} }

View File

@ -1,4 +1,5 @@
import {Component, ViewEncapsulation} from '@angular/core'; import {coerceNumberProperty} from '@angular/cdk/coercion';
import {Component} from '@angular/core';
/** /**
* @title Configurable slider * @title Configurable slider
@ -7,7 +8,6 @@ import {Component, ViewEncapsulation} from '@angular/core';
selector: 'slider-configurable-example', selector: 'slider-configurable-example',
templateUrl: 'slider-configurable-example.html', templateUrl: 'slider-configurable-example.html',
styleUrls: ['slider-configurable-example.css'], styleUrls: ['slider-configurable-example.css'],
encapsulation: ViewEncapsulation.None,
}) })
export class SliderConfigurableExample { export class SliderConfigurableExample {
autoTicks = false; autoTicks = false;
@ -24,8 +24,8 @@ export class SliderConfigurableExample {
get tickInterval(): number | 'auto' { get tickInterval(): number | 'auto' {
return this.showTicks ? (this.autoTicks ? 'auto' : this._tickInterval) : 0; return this.showTicks ? (this.autoTicks ? 'auto' : this._tickInterval) : 0;
} }
set tickInterval(v) { set tickInterval(value) {
this._tickInterval = Number(v); this._tickInterval = coerceNumberProperty(value);
} }
private _tickInterval = 1; private _tickInterval = 1;
} }

View File

@ -22,6 +22,10 @@ export class SnackBarComponentExample {
@Component({ @Component({
selector: 'snack-bar-component-example-snack', selector: 'snack-bar-component-example-snack',
templateUrl: 'snack-bar-component-example-snack.html', templateUrl: 'snack-bar-component-example-snack.html',
styles: [`.example-pizza-party { color: hotpink; }`], styles: [`
.example-pizza-party {
color: hotpink;
}
`],
}) })
export class PizzaPartyComponent {} export class PizzaPartyComponent {}

View File

@ -1,6 +1,14 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {Sort} from '@angular/material'; import {Sort} from '@angular/material';
export interface Dessert {
calories: number;
carbs: number;
fat: number;
name: string;
protein: number;
}
/** /**
* @title Sorting overview * @title Sorting overview
*/ */
@ -10,15 +18,15 @@ import {Sort} from '@angular/material';
styleUrls: ['sort-overview-example.css'], styleUrls: ['sort-overview-example.css'],
}) })
export class SortOverviewExample { export class SortOverviewExample {
desserts = [ desserts: Dessert[] = [
{name: 'Frozen yogurt', calories: '159', fat: '6', carbs: '24', protein: '4'}, {name: 'Frozen yogurt', calories: 159, fat: 6, carbs: 24, protein: 4},
{name: 'Ice cream sandwich', calories: '237', fat: '9', carbs: '37', protein: '4'}, {name: 'Ice cream sandwich', calories: 237, fat: 9, carbs: 37, protein: 4},
{name: 'Eclair', calories: '262', fat: '16', carbs: '24', protein: '6'}, {name: 'Eclair', calories: 262, fat: 16, carbs: 24, protein: 6},
{name: 'Cupcake', calories: '305', fat: '4', carbs: '67', protein: '4'}, {name: 'Cupcake', calories: 305, fat: 4, carbs: 67, protein: 4},
{name: 'Gingerbread', calories: '356', fat: '16', carbs: '49', protein: '4'}, {name: 'Gingerbread', calories: 356, fat: 16, carbs: 49, protein: 4},
]; ];
sortedData; sortedData: Dessert[];
constructor() { constructor() {
this.sortedData = this.desserts.slice(); this.sortedData = this.desserts.slice();
@ -26,19 +34,19 @@ export class SortOverviewExample {
sortData(sort: Sort) { sortData(sort: Sort) {
const data = this.desserts.slice(); const data = this.desserts.slice();
if (!sort.active || sort.direction == '') { if (!sort.active || sort.direction === '') {
this.sortedData = data; this.sortedData = data;
return; return;
} }
this.sortedData = data.sort((a, b) => { this.sortedData = data.sort((a, b) => {
let isAsc = sort.direction == 'asc'; const isAsc = sort.direction === 'asc';
switch (sort.active) { switch (sort.active) {
case 'name': return compare(a.name, b.name, isAsc); case 'name': return compare(a.name, b.name, isAsc);
case 'calories': return compare(+a.calories, +b.calories, isAsc); case 'calories': return compare(a.calories, b.calories, isAsc);
case 'fat': return compare(+a.fat, +b.fat, isAsc); case 'fat': return compare(a.fat, b.fat, isAsc);
case 'carbs': return compare(+a.carbs, +b.carbs, isAsc); case 'carbs': return compare(a.carbs, b.carbs, isAsc);
case 'protein': return compare(+a.protein, +b.protein, isAsc); case 'protein': return compare(a.protein, b.protein, isAsc);
default: return 0; default: return 0;
} }
}); });

View File

@ -2,7 +2,7 @@
{{!isEditable ? 'Enable edit mode' : 'Disable edit mode'}} {{!isEditable ? 'Enable edit mode' : 'Disable edit mode'}}
</button> </button>
<mat-horizontal-stepper [linear]="true" #stepper> <mat-horizontal-stepper linear #stepper>
<mat-step [stepControl]="firstFormGroup" [editable]="isEditable"> <mat-step [stepControl]="firstFormGroup" [editable]="isEditable">
<form [formGroup]="firstFormGroup"> <form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Fill out your name</ng-template> <ng-template matStepLabel>Fill out your name</ng-template>

View File

@ -12,9 +12,9 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
export class StepperEditableExample implements OnInit { export class StepperEditableExample implements OnInit {
firstFormGroup: FormGroup; firstFormGroup: FormGroup;
secondFormGroup: FormGroup; secondFormGroup: FormGroup;
isEditable: boolean = false; isEditable = false;
constructor(private _formBuilder: FormBuilder) { } constructor(private _formBuilder: FormBuilder) {}
ngOnInit() { ngOnInit() {
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({

View File

@ -2,7 +2,7 @@
{{!isOptional ? 'Enable optional steps' : 'Disable optional steps'}} {{!isOptional ? 'Enable optional steps' : 'Disable optional steps'}}
</button> </button>
<mat-horizontal-stepper [linear]="true" #stepper> <mat-horizontal-stepper linear #stepper>
<mat-step [stepControl]="firstFormGroup"> <mat-step [stepControl]="firstFormGroup">
<form [formGroup]="firstFormGroup"> <form [formGroup]="firstFormGroup">
<ng-template matStepLabel>Fill out your name</ng-template> <ng-template matStepLabel>Fill out your name</ng-template>

View File

@ -12,9 +12,9 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
export class StepperOptionalExample implements OnInit { export class StepperOptionalExample implements OnInit {
firstFormGroup: FormGroup; firstFormGroup: FormGroup;
secondFormGroup: FormGroup; secondFormGroup: FormGroup;
isOptional: boolean = false; isOptional = false;
constructor(private _formBuilder: FormBuilder) { } constructor(private _formBuilder: FormBuilder) {}
ngOnInit() { ngOnInit() {
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({

View File

@ -7,14 +7,14 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({ @Component({
selector: 'stepper-overview-example', selector: 'stepper-overview-example',
templateUrl: 'stepper-overview-example.html', templateUrl: 'stepper-overview-example.html',
styleUrls: ['stepper-overview-example.css'] styleUrls: ['stepper-overview-example.css'],
}) })
export class StepperOverviewExample implements OnInit { export class StepperOverviewExample implements OnInit {
isLinear = false; isLinear = false;
firstFormGroup: FormGroup; firstFormGroup: FormGroup;
secondFormGroup: FormGroup; secondFormGroup: FormGroup;
constructor(private _formBuilder: FormBuilder) { } constructor(private _formBuilder: FormBuilder) {}
ngOnInit() { ngOnInit() {
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({

View File

@ -14,7 +14,7 @@ export class StepperVerticalExample implements OnInit {
firstFormGroup: FormGroup; firstFormGroup: FormGroup;
secondFormGroup: FormGroup; secondFormGroup: FormGroup;
constructor(private _formBuilder: FormBuilder) { } constructor(private _formBuilder: FormBuilder) {}
ngOnInit() { ngOnInit() {
this.firstFormGroup = this._formBuilder.group({ this.firstFormGroup = this._formBuilder.group({

View File

@ -2,7 +2,7 @@ import {Component} from '@angular/core';
import {FormControl} from '@angular/forms'; import {FormControl} from '@angular/forms';
/** /**
* @title Tag group with dynamically changing tabs * @title Tab group with dynamically changing tabs
*/ */
@Component({ @Component({
selector: 'tab-group-dynamic-example', selector: 'tab-group-dynamic-example',

View File

@ -7,6 +7,6 @@
<nav mat-tab-nav-bar [backgroundColor]="background"> <nav mat-tab-nav-bar [backgroundColor]="background">
<a mat-tab-link *ngFor="let link of links" <a mat-tab-link *ngFor="let link of links"
(click)="activeLink = link" (click)="activeLink = link"
[active]="activeLink == link"> {{ link }} </a> [active]="activeLink == link"> {{link}} </a>
<a mat-tab-link disabled>Disabled Link</a> <a mat-tab-link disabled>Disabled Link</a>
</nav> </nav>

View File

@ -1,18 +1,5 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
/**
* @title Basic use of `<mat-table>` (uses display flex)
*/
@Component({
selector: 'table-basic-flex-example',
styleUrls: ['table-basic-flex-example.css'],
templateUrl: 'table-basic-flex-example.html',
})
export class TableBasicFlexExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}
export interface PeriodicElement { export interface PeriodicElement {
name: string; name: string;
position: number; position: number;
@ -32,3 +19,16 @@ const ELEMENT_DATA: PeriodicElement[] = [
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]; ];
/**
* @title Basic use of `<mat-table>` (uses display flex)
*/
@Component({
selector: 'table-basic-flex-example',
styleUrls: ['table-basic-flex-example.css'],
templateUrl: 'table-basic-flex-example.html',
})
export class TableBasicFlexExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}

View File

@ -1,18 +1,5 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
/**
* @title Basic use of `<table mat-table>`
*/
@Component({
selector: 'table-basic-example',
styleUrls: ['table-basic-example.css'],
templateUrl: 'table-basic-example.html',
})
export class TableBasicExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}
export interface PeriodicElement { export interface PeriodicElement {
name: string; name: string;
position: number; position: number;
@ -32,3 +19,16 @@ const ELEMENT_DATA: PeriodicElement[] = [
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]; ];
/**
* @title Basic use of `<table mat-table>`
*/
@Component({
selector: 'table-basic-example',
styleUrls: ['table-basic-example.css'],
templateUrl: 'table-basic-example.html',
})
export class TableBasicExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}

View File

@ -3,7 +3,7 @@
<button mat-raised-button (click)="shuffle()"> Shuffle </button> <button mat-raised-button (click)="shuffle()"> Shuffle </button>
<table mat-table [dataSource]="data" class="mat-elevation-z8"> <table mat-table [dataSource]="data" class="mat-elevation-z8">
<ng-container matColumnDef="{{column}}" *ngFor="let column of definedColumns"> <ng-container [matColumnDef]="column" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th> <th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element"> {{element[column]}} </td> <td mat-cell *matCellDef="let element"> {{element[column]}} </td>
</ng-container> </ng-container>

View File

@ -1,5 +1,25 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
}
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
];
/** /**
* @title Table dynamically changing the columns displayed * @title Table dynamically changing the columns displayed
*/ */
@ -9,13 +29,13 @@ import {Component} from '@angular/core';
templateUrl: 'table-dynamic-columns-example.html', templateUrl: 'table-dynamic-columns-example.html',
}) })
export class TableDynamicColumnsExample { export class TableDynamicColumnsExample {
definedColumns = ['name', 'weight', 'symbol', 'position']; displayedColumns: string[] = ['name', 'weight', 'symbol', 'position'];
columnsToDisplay = this.definedColumns.slice(); columnsToDisplay: string[] = this.displayedColumns.slice();
data: PeriodicElement[] = ELEMENT_DATA; data: PeriodicElement[] = ELEMENT_DATA;
addColumn() { addColumn() {
const randomColumn = Math.floor(Math.random() * this.definedColumns.length); const randomColumn = Math.floor(Math.random() * this.displayedColumns.length);
this.columnsToDisplay.push(this.definedColumns[randomColumn]); this.columnsToDisplay.push(this.displayedColumns[randomColumn]);
} }
removeColumn() { removeColumn() {
@ -37,23 +57,3 @@ export class TableDynamicColumnsExample {
} }
} }
} }
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
}
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
];

View File

@ -1,25 +1,6 @@
import {Component} from '@angular/core'; import {Component} from '@angular/core';
import {MatTableDataSource} from '@angular/material'; import {MatTableDataSource} from '@angular/material';
/**
* @title Table with filtering
*/
@Component({
selector: 'table-filtering-example',
styleUrls: ['table-filtering-example.css'],
templateUrl: 'table-filtering-example.html',
})
export class TableFilteringExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource(ELEMENT_DATA);
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
}
export interface PeriodicElement { export interface PeriodicElement {
name: string; name: string;
position: number; position: number;
@ -39,3 +20,20 @@ const ELEMENT_DATA: PeriodicElement[] = [
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'}, {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'}, {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]; ];
/**
* @title Table with filtering
*/
@Component({
selector: 'table-filtering-example',
styleUrls: ['table-filtering-example.css'],
templateUrl: 'table-filtering-example.html',
})
export class TableFilteringExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource(ELEMENT_DATA);
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
}

View File

@ -14,7 +14,7 @@ export interface Transaction {
templateUrl: 'table-footer-row-example.html', templateUrl: 'table-footer-row-example.html',
}) })
export class TableFooterRowExample { export class TableFooterRowExample {
displayedColumns = ['item', 'cost']; displayedColumns: string[] = ['item', 'cost'];
transactions: Transaction[] = [ transactions: Transaction[] = [
{item: 'Beach ball', cost: 4}, {item: 'Beach ball', cost: 4},
{item: 'Towel', cost: 5}, {item: 'Towel', cost: 5},

Some files were not shown because too many files have changed in this diff Show More