|
1 | | -import {bootstrap, onChange, NgIf, Component, Directive, View, Ancestor} from 'angular2/angular2'; |
| 1 | +import { |
| 2 | + bootstrap, |
| 3 | + onChange, |
| 4 | + NgIf, |
| 5 | + NgFor, |
| 6 | + Component, |
| 7 | + Directive, |
| 8 | + View, |
| 9 | + Ancestor |
| 10 | +} from 'angular2/angular2'; |
2 | 11 | import {formDirectives, NgControl, Validators, NgFormModel, FormBuilder} from 'angular2/forms'; |
3 | 12 |
|
4 | 13 | import {RegExpWrapper, print, isPresent} from 'angular2/src/facade/lang'; |
@@ -86,6 +95,13 @@ class ShowError { |
86 | 95 | <show-error control="lastName" [errors]="['required']"></show-error> |
87 | 96 | </p> |
88 | 97 |
|
| 98 | + <p> |
| 99 | + <label for="country">Country</label> |
| 100 | + <select id="country" ng-control="country"> |
| 101 | + <option *ng-for="#c of countries" [value]="c">{{c}}</option> |
| 102 | + </select> |
| 103 | + </p> |
| 104 | +
|
89 | 105 | <p> |
90 | 106 | <label for="creditCard">Credit Card</label> |
91 | 107 | <input type="text" id="creditCard" ng-control="creditCard"> |
@@ -113,16 +129,18 @@ class ShowError { |
113 | 129 | <button type="submit" [disabled]="!f.form.valid">Submit</button> |
114 | 130 | </form> |
115 | 131 | `, |
116 | | - directives: [formDirectives, ShowError] |
| 132 | + directives: [formDirectives, NgFor, ShowError] |
117 | 133 | }) |
118 | 134 | class ModelDrivenForms { |
119 | 135 | form; |
| 136 | + countries = ['US', 'Canada']; |
120 | 137 |
|
121 | 138 | constructor(fb: FormBuilder) { |
122 | 139 | this.form = fb.group({ |
123 | 140 | "firstName": ["", Validators.required], |
124 | 141 | "middleName": [""], |
125 | 142 | "lastName": ["", Validators.required], |
| 143 | + "country": ["Canada", Validators.required], |
126 | 144 | "creditCard": ["", Validators.compose([Validators.required, creditCardValidator])], |
127 | 145 | "amount": [0, Validators.required], |
128 | 146 | "email": ["", Validators.required], |
|
0 commit comments