How to โ€œremoveโ€ a variable from scope in angular.js

According to my knowledge, when we bind a variable to an area, a clock is applied to it and it is checked every digest cycle. A good rule of thumb is that we should not track more than 2,000 variables at a given time.

My question is how to remove an existing variable from scope. For example, $scope.var1=1 say that I had to create it for one-time use. Is it possible for me to โ€œremoveโ€ it from the scope or view the variable for the duration of the scope?

EDIT:

From the comments below, I understand that you must delete the watch manually or it will be destroyed when the area is destroyed. However, I still do not understand how you will remove the clock for variables that are set using directives such as ngModel?

+7
javascript angularjs
source share
1 answer

You can simply use the delete keyword:

 delete $scope.var1; 
+32
source share

All Articles