JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<div ng-app ng-controller="MyController">
<button ng-click="addObj()">Add new item</button>
<ul>
<li ng-repeat="obj in main.list">{{obj.$$hashKey}}</li>
</ul>
</div>
JavaScript
function Obj()
{
this.id = Math.floor(Math.random() * 100000);
}
var MyController = function($scope, $timeout)
{
$scope.main = {
list: []
};
$scope.$watch("main", function(newValue, oldValue)
{
if(newValue == oldValue)
return;
var lastObj = $scope.main.list[$scope.main.list.length - 1];
/*******************************
/ HERE, IT'S UNDEFINED HERE!
********************************/
$timeout(function(){console.log(lastObj.$$hashKey)}); // undefined
/*******************************
/ ^^^^^^^^^^^^^^^^^^^^^^^^
********************************/
}, true);
$scope.addObj = function()
{
$scope.main.list.push(new Obj());
};
};