yah. you can also do $scope.user = {} too.
On Thu Nov 06 2014 at 1:21:13 PM Mohammad Kamruddin Ali Ahemad <
[email protected]> wrote:
> Ok. Got it. I guess we need to do $scope.user = new Object(); before
> doing $scope.user.firstName as $scope.user is not defined yet.
>
>
> On Friday, 7 November 2014 02:48:18 UTC+5:30, Mohammad Kamruddin Ali
> Ahemad wrote:
>>
>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.