Please find the below program which is working as expected.

<!DOCTYPE html>
<html lang="en">

<head>
<script 
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js";></script>
</head>

<body>
<div ng-app="" ng-controller="formController">
  <form novalidate>
    First Name:<br>
    <input type="text" ng-model="user.firstName"><br>
    Last Name:<br>
    <input type="text" ng-model="user.lastName">
    <br><br>
    <button ng-click="reset()">RESET</button>
  </form>
  <p>form = {{user }}</p>
  <p>master = {{master}}</p>
</div>

<script>
function formController ($scope) {
    $scope.master = {firstName:"John", lastName:"Doe"};
$scope.user= {firstName:"Kamruddin", lastName:"Ali"};
    $scope.reset = function() {
        $scope.user = angular.copy($scope.master);
    };
    //$scope.reset();
}
</script>

</body>
</html>



Now lets tweak this program a little and write like this. it is not working 
why?
<!DOCTYPE html>
<html lang="en">

<head>
<script 
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js";></script>
</head>

<body>
<div ng-app="" ng-controller="formController">
  <form novalidate>
    First Name:<br>
    <input type="text" ng-model="user.firstName"><br>
    Last Name:<br>
    <input type="text" ng-model="user.lastName">
    <br><br>
    <button ng-click="reset()">RESET</button>
  </form>
  <p>form = {{user }}</p>
  <p>master = {{master}}</p>
</div>

<script>
function formController ($scope) {
    $scope.master = {firstName:"John", lastName:"Doe"};
$scope.user.firstName = "Kamruddin";
$scope.user.lastName= "Ali";
    $scope.reset = function() {
        $scope.user = angular.copy($scope.master);
    };
    //$scope.reset();
}
</script>

</body>
</html>


-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to