link function in directive
If you want add template than add your function in link
by Jscaptcha
HTML
<script src="https://code.angularjs.org/angular-1.0.0rc5.min.js"></script>
<div ng-app='directiveApp' ng-controller='MessageController'>
<my-table items="items" columns="item,address,contact"></my-table>
</div>
JavaScript
angular.module('directiveApp',[])
.controller('MessageController', function($scope) {
$scope.items = [
{itemname: 'Item 1', address: 'addressOne ', contacts: '77565765'},
{itemname: 'Item 2', address: 'addressTwo', contacts: '99978665'}
];
$scope.message = 'hello, from the external controller';
})
.directive('myTable',function(){
return{
restrict:'E',
link:function(scope,element,attr)
{
scope.dataItems = scope.$eval(attr.items);
scope.columns = attr.columns.split(',');
},
template:"<div><table><tr><td ng-repeat='column in columns'>{{column}}</td></tr> <tr ng-repeat='item in dataItems'><td>{{item.itemname}}</td><td>{{item.address}}</td><td>{{item.contacts}}</td></tr> </table></div>"
}
});