I've a directive to create a list of elements to control pagination and filters, I use it in several points of my application.
I want to know what is the best way to add custom methods to the directive.
Example:
angular.module('example').directive('list', function () {
return {
scope: {
elements: '=ngModel',
filters: '=?'
},
restrict: 'E',
transclude: true,
templateUrl: '/static/templates/list.html',
controller: function () {
// Some stuff of pagination and filters functions
}
}
}
My directive template looks like:
<div class="list">
<!-- Pagination stuff -->
<div ng-transclude></div>
<!-- Pagination stuff -->
</div>
And I use the directive like this:
<list elements="elements">
<div ng-controller="CustomMethodsController">
<div class="col-xs-6">
{{result.element_1}}
</div>
<div class="col-xs-6">
{{result.element_2}}
</div>
</div>
</list>
I don't know whether create a controller inside a directive is a good practice or there's a better way to achieve this.
Thanks in advance.