Pass to the function (by reference) a variable in the area

Is there a way (in angularJS) to pass a variable in an area in a function by reference (to change it)? I tried, but the variable does not change. Here is my code

$scope.modifyVar = function (myVariable){ myVariable = 92; } $scope.modifyVar($scope.txtNumberOfChuck); 
+5
source share
1 answer

You cannot pass a variable by reference in Javascript. However, you can pass the complete object and change your values.

In your case, you can pass the $ scope object and then change the value of the property. Something like that:

 $scope.modifyVar = function (myObj){ myObj.txtNumberOfChuck = 92; } $scope.modifyVar($scope); 
+6
source

Source: https://habr.com/ru/post/1206612/


All Articles