In this section, we write a form program that uses ANGULARJS to detect and complete the acquisition and copying of form attributes.
In Angularjs, it also supports automatic detection of multiple controls in HTML5, such as text, number, URL, email, radio, checkbox, and so on.
Data from form forms can be automatically copied by Anuglar.copy ().
The code reference is as follows:
<!doctype html>Name:<input type= "text" ng-model= "User.Name" required/><br> e-mail: <input type= "Email" Ng-model = "User.email" Required/><br> Age: <input type= "number" ng-model= "User.age" min= "1" max= "the" Re quired/><br> Gender: <input type= "Radio" ng-model= "User.gender" value= "male"/>male <input type= "Radio" ng-model= "User.gender" value= "female"/>female<br> <button ng -click= "Reset ()" >reset</button> <button ng-click= "Update (user)" >save</button> </form> <pre>form = {{User | json}}</pre> <pre>master = {{master | json}} </pre> </div> <style type= "Text/css" >. CSS-form input.ng-invalid.ng-Dirty {background-color: #FA787E; }. CSS-form input.ng-valid.ng-Dirty {background-color: #78FA89; } </style> <script type= "Text/javascript" >functionController ($scope) {$scope. master= {}; $scope. Update=function(user) {$scope. master=angular.copy (user); }; $scope. Reset=function() {$scope. User=angular.copy ($scope. master); }; $scope. Reset (); } </script> </body>When the form data is filled in correctly, the background is green and the reality is red when the data is illegal.
Use Save to save the data in the form to master, and use reset to copy the data from master to the form.
Run Results reference:
"AngularJS"--5 form