Try this code, it can help you:
http://plnkr.co/edit/L1NwUnNePofyRAQ6GVIg?p=preview
var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.name = 'World'; $scope.masterData = [ { entry: 'dunno' }, { entry: 'stuff' } ] }) app.directive('vessel', function() { return { replace: true, scope: { data: '=', speciality: '@' }, link: function(scope) { scope.updateData = function() { scope.data.entry = scope.speciality; } }, template: '<div>{{data.entry}} <button ng-click="updateData()">update</button></div>' } });
And the template:
<body ng-controller="MainCtrl"> <p>Master data {{masterData | json}}</p> <div vessel data="masterData[0]" speciality="eggs"></div> <div vessel data="masterData[1]" speciality="bacon"></div> </body>
So, we have separate data models for each directive, which are updated at the user input that meets your requirements. Right?
source share