Ng-table(ng-table site) can put $data
variable outside from their directive to 'user' domain. As long as I know, I can use and abuse this $data
variable as I like as long as it happens inside <table ng-table></table>
like this :
<table ng-table="vm.tableParams" class="table" show-filter="true">
<tr ng-repeat="user in $data"> <---- where is this $data comes from ?
</tr>
</table>
I want to do the same with my directive, so I made this:
[JS]
angular.module('app', [])
.controller('Controller', ['$scope', function($scope) {
$scope.variable = "some random variable";
}])
.directive('myTable', function() {
return {
restrict : 'E',
transclude : true,
templateUrl : 'my-table.html',
controller: function($scope){
$scope.foo = "hello world";
}
};
});
[HTML my-table.html]
<div ng-transclude></div>
[HTML index.html]
<my-table ng-model="variable">
<div>{{ foo }}</div> <!-- foo comes from directive, not controller -->
</my-table>
it works! working sample,
But when I add scope
to directive :
return {
restrict: 'E',
transclude: true,
scope:{
ngModel : "="
},
templateUrl: 'my-table.html',
controller: function($scope){
$scope.foo = "hello world";
}
}
It destroys foo
variable so it doesn't work anymore not working sample.
I just want foo
variable INSIDE the directive to be exposed OUTSIDE so I can use it in index.html
just like ng-table
example above. How to achive this?