I asked yesterday a similar question yet there is a difference.
I'm trying to create a generic function that will change a scope object(not primitive)
yet it seems not to be working and I don't understand why?
My code:
webApp.controller ('VotesCtrl', function ($scope) {
$scope.param = {name: 'Ron', age: 18};
change($scope.param);
function change(contextParam) {
contextParam = {name:'dan', age: 12};
}
});
It seems change function does not make any change on $scope.param even though I'm
passing a reference.
When I'm doing the change like the code below, it is working!
webApp.controller ('VotesCtrl', function ($scope) {
$scope.param = {name: 'Ron', age: 18};
change($scope.param);
function change(contextParam) {
contextParam.name = 'dan';
contextParam.age = 12;
}
});
What am I doing wrong? how can you explain this behavior?