I have a scope variable, $scope.test
. If I pass this variable in a function that is invoked in a template as an argument and then I try to change it in the controller, it seems that the original $scope.test
does not change. Only the local variable, foo changes. But isn't foo a reference to $scope.test
?
var mod = angular.module('app', []);
mod.controller('myCtrl', function($scope) {
$scope.test = 'test';
$scope.doSomething = function(foo) {
foo = 'scope.test should change';
}
})
Here, I'm passing test to the doSomething function which is in the controller above.
<body ng-app='app'>
<div ng-controller='myCtrl'>
<button ng-click="doSomething(test)">testing</button>
<h1>{{test}}</h1>
</div>
</body>
Here's the plunker: http://plnkr.co/edit/JBsos0qVJP47WgfD9Fee?p=preview