I'm creating two directives which use the same controller, as a result I see that both directives share data among controller. What I want is that data to be UNIQUE per directive, so data shouldn't be shared.
var app = angular.module("app",[]);
app.controller('myCtrl', function($scope){
$scope.data = {
name: 'Javier'
};
});
app.directive('dir1', function(){
return {
template: "<div style='background:red'><input type='text' ng-model='data.name'>{{data.name}}</div>",
controller: "myCtrl"
};
});
app.directive('dir2', function(){
return {
template: "<div style='background:yellow'><input type='text' ng-model='data.name'>{{data.name}}</div>",
controller: "myCtrl"
};
});
https://jsbin.com/vetikuvada/1/edit?html,js,output
So in my example I want is when I edit the text in one of the textboxes it doesn't trigger changes in the other textbox. I know that controllers are deployed with different instances but somehow they share the scope, I need this to be completely different. Is this possible?
The example is a small part of a very complex app, so I must be able to do it using this approach and no other else.