When passing an object to a ng-click
function, the object seems to lose its reference. What is the reason?
<div ng-app="app" ng-controller="controller">
<p>
<u>Object</u> : {{ obj | json }}
</p>
<p>
<button ng-click="obj = {}">obj = {}</button> <!-- works -->
<button ng-click="voidIt(obj)">voidIt(obj)</button> <!-- doesn't work -->
</p>
<p>
<button ng-click="reset()">Reset obj</button>
</p>
</div>
angular.module('app', []).controller('controller',
function($scope) {
$scope.voidIt = function(object) {
object = {}
}
$scope.reset = function() {
$scope.obj = { prop: "value" }
}
$scope.reset();
});