I'm iterating over an array of objects via ngRepat. Each one gets a directive. Inside that directive I'm trying to assign to the scope variable which at first works fine, but upon changing the array it gets resetted.
<test-directive obj="obj" ng-repeat="obj in objects"></test-directive>
app.directive('testDirective', function() {
return {
restrict: 'E',
scope: { obj: '=' },
template: '<div><a ng-click="doTheThing()">{{obj.title}}</a></div>',
link: function($scope, $element, $attrs) {
$scope.doTheThing = function() {
$scope.obj = { changed: true, title: 'Is changed.'};
};
}
};
});
Demo: https://jsfiddle.net/byjvey2b/ (Click the items to apply the change, upon clicking verify which adds a new element, everything is reset).
Simply changing the attributes accordingly, instead of the whole object, won't help me, I'm actually reassigning different subclasses in my own code.