I am running into some issue regarding isolated scopes. I have a directive which i need to use at many places and its controller has some helper functions for the directive. The directive does create isolated scopes but the template refers to the parent scope. Below is a plunk to demo that issue
http://plnkr.co/edit/LQnlSjMHeatMkmkYZyfk
$scope.text = "test";
is to demo that the property does not change in the isolated scope and refers to the parent scope. Due to this issue i am unable to call the helper functions for each isolated scope. I hope I am able to describe my problem properly.
Below is the code
HTML:
<body ng-controller="MainCtrl">
<div transfer-box style="">
{{text}}
<div ng-if="refresh" ></div>
{{refresh}}
</div>
<div transfer-box style="">
{{text}}
<div ng-if="refresh" ></div>
{{refresh}}
</div>
</body>
Javascript:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.text = 'World';
console.log("parent scope id "+ $scope.$id);
});
app.directive('transferBox', function() {
return {
restrict: 'EA',
xreplace: true,
transclude: true,
scope:true,
template: '<div class="container-fluid" style="height:100%" ng-transclude></div>',
controller:'transferBoxCtrl'
};
})
app.controller('transferBoxCtrl',['$scope',function($scope){
console.log($scope.$id);
$scope.refresh = true;
$scope.text = "test";
}])