Skip to content

Commit b062c9c

Browse files
authored
docs(autocomplete): copy over autocomplete example (#3340)
1 parent d1abc9e commit b062c9c

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/examples/autocomplete-overview-example.css

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<md-input-container>
2+
<input mdInput placeholder="State" [mdAutocomplete]="auto" [formControl]="stateCtrl">
3+
</md-input-container>
4+
5+
<md-autocomplete #auto="mdAutocomplete">
6+
<md-option *ngFor="let state of filteredStates | async" [value]="state">
7+
{{ state }}
8+
</md-option>
9+
</md-autocomplete>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {Component} from '@angular/core';
2+
import {FormControl} from '@angular/forms';
3+
import 'rxjs/add/operator/startWith';
4+
5+
@Component({
6+
selector: 'autocomplete-overview-example',
7+
templateUrl: './autocomplete-overview-example.html',
8+
})
9+
export class AutocompleteOverviewExample {
10+
stateCtrl: FormControl;
11+
filteredStates: any;
12+
13+
states = [
14+
'Alabama',
15+
'Alaska',
16+
'Arizona',
17+
'Arkansas',
18+
'California',
19+
'Colorado',
20+
'Connecticut',
21+
'Delaware',
22+
'Florida',
23+
'Georgia',
24+
'Hawaii',
25+
'Idaho',
26+
'Illinois',
27+
'Indiana',
28+
'Iowa',
29+
'Kansas',
30+
'Kentucky',
31+
'Louisiana',
32+
'Maine',
33+
'Maryland',
34+
'Massachusetts',
35+
'Michigan',
36+
'Minnesota',
37+
'Mississippi',
38+
'Missouri',
39+
'Montana',
40+
'Nebraska',
41+
'Nevada',
42+
'New Hampshire',
43+
'New Jersey',
44+
'New Mexico',
45+
'New York',
46+
'North Carolina',
47+
'North Dakota',
48+
'Ohio',
49+
'Oklahoma',
50+
'Oregon',
51+
'Pennsylvania',
52+
'Rhode Island',
53+
'South Carolina',
54+
'South Dakota',
55+
'Tennessee',
56+
'Texas',
57+
'Utah',
58+
'Vermont',
59+
'Virginia',
60+
'Washington',
61+
'West Virginia',
62+
'Wisconsin',
63+
'Wyoming',
64+
];
65+
66+
constructor() {
67+
this.stateCtrl = new FormControl();
68+
this.filteredStates = this.stateCtrl.valueChanges
69+
.startWith(null)
70+
.map(name => this.filterStates(name));
71+
}
72+
73+
filterStates(val: string) {
74+
return val ? this.states.filter((s) => new RegExp(val, 'gi').test(s)) : this.states;
75+
}
76+
77+
}

0 commit comments

Comments
 (0)