JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="testmod">
<div ng-controller="TestCtrl">
<test-directive obj="obj" updated="replaceObject(obj, newObj)" ng-repeat="obj in objects">
</test-directive>
<button ng-click="objects.push({title:'nope'})">Verify</button>
</div>
</div>
JavaScript
var app = angular.module('testmod', []);
app.controller('TestCtrl', function($scope) {
$scope.objects = [
{unchanged:true, title:'Is not changed'},
{unchanged:true, title: 'Is also not changed'}
];
$scope.replaceObject = function(object, newObject) {
var i = $scope.objects.indexOf(object);
$scope.objects.splice(i, 1, newObject);
}
});
app.directive('testDirective', function() {
return {
restrict: 'E',
scope: {
obj: '=',
updated: '&'
},
template: '<div><a ng-click="doTheThing()">{{obj.title}}</a></div>',
link: function($scope, $element, $attrs) {
$scope.doTheThing = function() {
$scope.updated({newObj: { changed: true, title: 'Is changed.'}});
};
}
};
});