Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "delete" a variable from scope in angular.js [duplicate]

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 ?

like image 484
Kiran Yallabandi Avatar asked Aug 19 '15 19:08

Kiran Yallabandi


1 Answers

You can simply use the delete keyword:

delete $scope.var1;
like image 105
aghidini Avatar answered Oct 20 '22 07:10

aghidini