Here is my code:
<div ng-controller="TestController">
<h1 ng-click="click()">{{person.name}}</h1>
</div>
<script type="text/javascript">
var app = angular.module('app', []);
app.controller('TestController', function ($scope) {
var p = $scope.person = {
name: 'Br'
};
$scope.click = function () {
p = {};
}
});
</script>
When I click on the <h1>, I reset the p object, so I expect empty in the h1 tag.
Because I think the variable p has the same reference as $scope.person, which point to the same object.
In fact nothing changed when I clicked, only if I reset the $scope.person = {}.
So why it doesn't work as I expect? What's wrong in my thought?