-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(autocomplete): copy over autocomplete example (#3340)
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<md-input-container> | ||
<input mdInput placeholder="State" [mdAutocomplete]="auto" [formControl]="stateCtrl"> | ||
</md-input-container> | ||
|
||
<md-autocomplete #auto="mdAutocomplete"> | ||
<md-option *ngFor="let state of filteredStates | async" [value]="state"> | ||
{{ state }} | ||
</md-option> | ||
</md-autocomplete> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl} from '@angular/forms'; | ||
import 'rxjs/add/operator/startWith'; | ||
|
||
@Component({ | ||
selector: 'autocomplete-overview-example', | ||
templateUrl: './autocomplete-overview-example.html', | ||
}) | ||
export class AutocompleteOverviewExample { | ||
stateCtrl: FormControl; | ||
filteredStates: any; | ||
|
||
states = [ | ||
'Alabama', | ||
'Alaska', | ||
'Arizona', | ||
'Arkansas', | ||
'California', | ||
'Colorado', | ||
'Connecticut', | ||
'Delaware', | ||
'Florida', | ||
'Georgia', | ||
'Hawaii', | ||
'Idaho', | ||
'Illinois', | ||
'Indiana', | ||
'Iowa', | ||
'Kansas', | ||
'Kentucky', | ||
'Louisiana', | ||
'Maine', | ||
'Maryland', | ||
'Massachusetts', | ||
'Michigan', | ||
'Minnesota', | ||
'Mississippi', | ||
'Missouri', | ||
'Montana', | ||
'Nebraska', | ||
'Nevada', | ||
'New Hampshire', | ||
'New Jersey', | ||
'New Mexico', | ||
'New York', | ||
'North Carolina', | ||
'North Dakota', | ||
'Ohio', | ||
'Oklahoma', | ||
'Oregon', | ||
'Pennsylvania', | ||
'Rhode Island', | ||
'South Carolina', | ||
'South Dakota', | ||
'Tennessee', | ||
'Texas', | ||
'Utah', | ||
'Vermont', | ||
'Virginia', | ||
'Washington', | ||
'West Virginia', | ||
'Wisconsin', | ||
'Wyoming', | ||
]; | ||
|
||
constructor() { | ||
this.stateCtrl = new FormControl(); | ||
this.filteredStates = this.stateCtrl.valueChanges | ||
.startWith(null) | ||
.map(name => this.filterStates(name)); | ||
} | ||
|
||
filterStates(val: string) { | ||
return val ? this.states.filter((s) => new RegExp(val, 'gi').test(s)) : this.states; | ||
} | ||
|
||
} |