If formname is a json object, then the comparison will be done as a
reference, add "true" as third parameter to the watch call.
$scope.$parent.$watch('formName',function (formName){
}, *true*):
Just beware performance impacts with this:
- When objectEquality == true, inequality of the watchExpression is
determined according to the angular.equals
<https://docs.angularjs.org/api/ng/function/angular.equals> function. To
save the value of the object for later comparison, the angular.copy
<https://docs.angularjs.org/api/ng/function/angular.copy> function is
used. This therefore means that watching complex objects will have adverse
memory and performance implications.
On Wednesday, May 20, 2015 at 10:10:02 AM UTC-4, Soorya Prakash wrote:
>
> Hi,
> I am having scope variable like *formName* as a json object in parent
> controller and and watching from child controller using $watch. On
> submitting the form i am making the *formName *as null and then again
> assigning the value .But the $watch function was not working and the
> *formName
> *still holds the last assigned value. Like below.
>
>
> In child controller
> $scope.$parent.$watch('*formName*',function (formName){
> }):
>
>
> In parent controler
>
> $scope.formname = null;
> function onSubmit(){
> //after api call
> $scope.formName = null;
> $timeout(function(){
> $scope.formName = (updated data)
> })
> }
>
>
>
--
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.