According to my knowledge when we attach a variable to the scope , watches are applied to it and it is checked every digest cycle. A good rule of thumb is that we should not have more than 2000 variables being watched at a given time.
My question is how do you remove an already present variable from scope. For example $scope.var1=1
say I had to create it for a one time use. Is it possible for me to "delete" it from the scope or will the variable be watched for the life time of the scope ?
EDIT :
From the comments below I understand that you are supposed to remove the watches manually or they get destroyed when the scope gets destroyed. However I am still unclear as to how will you remove watches for variables which are set by directives such as ngModel ?
You can simply use the delete
keyword:
delete $scope.var1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With