I've been trying to create a generic function in angular that changes a $scope parameters value.
I've been wondering why I cannot pass $scope.var as an argument to a function e.g.:
webApp.controller ('VotesCtrl', function ($scope) {
$scope.param = 42;
change($scope.param);
function change(contextParam) {
contextParam = (Math.random()*100)+1;
};
});
When I ran this function $scope.param remains 42.
Is there an alternative besides:
webApp.controller ('VotesCtrl', function ($scope) {
$scope.param = 42;
change('param');
function change(contextParam) {
$scope[contextParam] = (Math.random()*100)+1;
};
});