Advertisement
Guest User

Untitled

a guest
Feb 27th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Angular practice</title>
  4. </head>
  5. <body>
  6. <div ng-app="" ng-controller="studentController">
  7. <form name="studentForm" novalidate>
  8. <table>
  9. <tr>
  10. <td>first name</td>
  11. <td><input name="firstname" type="text" ng-model="firstName" required>
  12. <span style="color: red;" ng-show="studentForm.firstname.$dirty && studentForm.firstname.$invalid">
  13. <span ng-show="studentForm.firstname.$error.required">enter first name</span>
  14. </span>
  15. </td>
  16. </tr>
  17. <tr>
  18. <td>last name</td>
  19. <td><input name="lastname" type="text" ng-model="lastName" required>
  20. <span style="color: red;" ng-show="studentForm.lastname.$dirty && studentForm.lastname.$invalid">
  21. <span ng-show="studentForm.lastname.$error.required">enter last name</span>
  22. </span>
  23. </td>
  24. </tr>
  25. <tr>
  26. <td>email</td>
  27. <td><input name="email" type="email" ng-model="email" required>
  28. <span style="color: red;" ng-show="studentForm.email.$dirty && studentForm.email.$invalid">
  29. <span ng-show="studentForm.email.$error.required">enter email ID</span>
  30. <span ng-show="studentForm.email.$error.email">Invalid email</span>
  31. </span>
  32. </td>
  33. </tr>
  34. <tr>
  35. <td><button ng-click="reset()">Reset</button></td>
  36. <td><button ng- disabled="studentForm.firstname.$dirty &&
  37. studentForm.firstname.$invalid ||
  38. studentForm.lastname.$dirty && studentForm.lastname.$invalid||
  39. studentForm.email.$dirty && studentForm.email.$invalid"
  40. ng-click="submit()">Submit</button>
  41. </td>
  42. </tr>
  43. </table>
  44. </form>
  45. </div>
  46.  
  47. <script>
  48. function studentController($scope){
  49. $scope.reset = function(){
  50. $scope.firstName = "uthej";
  51. $scope.lastName = "ks";
  52. $scope.email = "uthej@gmail.com";
  53. }
  54. $scope.reset();
  55. }
  56. </script>
  57. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  58. </body>
  59. </html>
  60.  
  61. <div ng-app="myApp" ng-controller="studentController">
  62.  
  63. var app = angular.module('myApp', []);
  64. app.controller('studentController', function ($scope) {
  65. $scope.reset = function () {
  66. $scope.firstName = "uthej";
  67. $scope.lastName = "ks";
  68. $scope.email = "uthej@gmail.com";
  69. }
  70. $scope.reset();
  71. });
  72.  
  73. <div ng-app="demoApp" ng-controller="studentController">
  74. <form name="studentForm" novalidate>
  75. // form fields will goes here....
  76. </form>
  77. </div>
  78.  
  79. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  80. <script>
  81. var app = angular.module("demoApp", []);
  82. app.controller("studentController", function($scope){
  83. $scope.reset = function(){
  84. $scope.firstName = "uthej";
  85. $scope.lastName = "ks";
  86. $scope.email = "uthej@gmail.com";
  87. };$scope.reset();
  88.  
  89. });
  90. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement