angular.copy
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.master = {}; $scope.reset = function() { // copy data from master to user $scope.user = angular.copy($scope.master); }; $scope.saveUser = function(user) { // copy user data in master angular.copy(user, $scope.master); }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form novalidate class="simple-form"> <label>Name: <input type="text" ng-model="user.name" /></label><br /> <label>Email: <input type="email" ng-model="user.email" /></label><br /> <label>Phone: <input type="text" ng-model="user.phone" /></label><br /> <button ng-click="reset()">RESET</button> <button ng-click="saveUser(user)">SAVE USER</button> <pre>user = {{user | json}}</pre> <pre>master = {{master | json}}</pre> </form> </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.master = {}; $scope.reset = function() { // copy data from master to user $scope.user = angular.copy($scope.master); }; $scope.saveUser = function(user) { // copy user data in master angular.copy(user, $scope.master); }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form novalidate class="simple-form"> <label>Name: <input type="text" ng-model="user.name" /></label><br /> <label>Email: <input type="email" ng-model="user.email" /></label><br /> <label>Phone: <input type="text" ng-model="user.phone" /></label><br /> <button ng-click="reset()">RESET</button> <button ng-click="saveUser(user)">SAVE USER</button> <pre>user = {{user | json}}</pre> <pre>master = {{master | json}}</pre> </form> </div> </div> </body> </html>
Copyrights@tutorialsplane.com