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 | <form ng-submit="ctrl.submit()" name="myForm"> |
| 10 | <input type="text" |
| 11 | name="uname" |
| 12 | placeholder="username" |
| 13 | ng-model="ctrl.user.username" |
| 14 | required |
| 15 | ng-minlength="4"/> |
| 16 | <span ng-show="myForm.uname.$error.required"> |
| 17 | This is a required field |
| 18 | </span> |
| 19 | <span ng-show="myForm.uname.$error.minlength"> |
| 20 | Minimum length required is 4 |
| 21 | </span> |
| 22 | <span ng-show="myForm.uname.$invalid"> |
| 23 | This field is invalid |
| 24 | </span> |
| 25 | <br/> |
| 26 | |
| 27 | <input type="password" |
| 28 | name="pwd" |
| 29 | placeholder="password" |
| 30 | ng-model="ctrl.user.password" |
| 31 | required/> |
| 32 | <span ng-show="myForm.pwd.$error.required"> |
| 33 | This is a required field |
| 34 | </span> |
| 35 | <br/> |
| 36 | |
| 37 | <input type="submit" |
| 38 | value="Submit" |
| 39 | ng-disabled="myForm.$invalid"/> |
| 40 | </form> |
| 41 | |
| 42 | <script type="text/javascript"> |
| 43 | angular.module('notesApp', []) |
| 44 | .controller('MainCtrl', [function () { |
| 45 | var self = this; |
| 46 | self.submit = function () { |
| 47 | console.log('Submit: ', self.user); |
| 48 | }; |
| 49 | }]); |
| 50 | </script> |
| 51 | |
| 52 | </body> |
| 53 | </html> |