AngularJs get Form Input Value
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.getFormData = ' '; $scope.getFormData = function(user) { // copy form data $scope.userData = angular.copy(user); // or you can also access data as below //$scope.userName = user.name; // give name //$scope.userEmail = user.email; // give email //$scope.userPhone = user.phone; // give phone //$scope.userLocation = user.location; //give location }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form action="javascript:void(0)"> Name: <input type="text" ng-model="user.name" /><br /> Email : <input type="email" ng-model="user.email" /><br /> Phone: <input type="text" ng-model="user.phone" /><br> Location: <input type="text" ng-model="user.location" /><br> <button ng-click="getFormData(user)">SAVE</button> </form> <p>User Data Json = {{userData | json}}</p> <p>Name = {{userData.name}}</p> <p>Email = {{userData.email}}</p> <p>Phone = {{userData.phone}}</p> <p>Location = {{userData.location}}</p> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.getFormData = ' '; $scope.getFormData = function(user) { // copy form data $scope.userData = angular.copy(user); // or you can also access data as below //$scope.userName = user.name; // give name //$scope.userEmail = user.email; // give email //$scope.userPhone = user.phone; // give phone //$scope.userLocation = user.location; //give location }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form action="javascript:void(0)"> Name: <input type="text" ng-model="user.name" /><br /> Email : <input type="email" ng-model="user.email" /><br /> Phone: <input type="text" ng-model="user.phone" /><br> Location: <input type="text" ng-model="user.location" /><br> <button ng-click="getFormData(user)">SAVE</button> </form> <p>User Data Json = {{userData | json}}</p> <p>Name = {{userData.name}}</p> <p>Email = {{userData.email}}</p> <p>Phone = {{userData.phone}}</p> <p>Location = {{userData.location}}</p> </div> </div> </body> </html>
Copyrights@tutorialsplane.com