Simon Hunt | d7c203c | 2014-12-09 16:51:49 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html ng-app="notesApp"> |
| 3 | <head> |
| 4 | <title>Notes App</title> |
| 5 | <script src="../../tp/angular.js"></script> |
| 6 | </head> |
| 7 | <body ng-controller="MainCtrl as ctrl"> |
| 8 | |
| 9 | <div> |
| 10 | <select ng-model="ctrl.selectedCountryId" |
| 11 | ng-options="c.id as c.label for c in ctrl.countries"> |
| 12 | </select> |
| 13 | Selected Country ID: {{ctrl.selectedCountryId}} |
| 14 | </div> |
| 15 | |
| 16 | <div> |
| 17 | <select ng-model="ctrl.selectedCountry" |
| 18 | ng-options="c.label for c in ctrl.countries track by c.id"> |
| 19 | </select> |
| 20 | Selected Country: {{ctrl.selectedCountry}} |
| 21 | </div> |
| 22 | |
| 23 | <script type="text/javascript"> |
| 24 | angular.module('notesApp', []) |
| 25 | .controller('MainCtrl', [function () { |
| 26 | var self = this; |
| 27 | |
| 28 | self.countries = [ |
| 29 | {label: 'UK', id: 1}, |
| 30 | {label: 'USA', id: 2}, |
| 31 | {label: 'France', id: 3}, |
| 32 | {label: 'Italy', id: 4} |
| 33 | ]; |
| 34 | var first = self.countries[0]; |
| 35 | self.selectedCountryId = first.id; |
| 36 | self.selectedCountry = first; |
| 37 | }]); |
| 38 | </script> |
| 39 | |
| 40 | </body> |
| 41 | </html> |