I would like to make an universal directive in which the user can easily insert any HTML for the header and footer.
This is my HTML code:
<datagrid
id="testing"
url="google.com/test">
<header>
<p>header</p>
</header>
<footer>
<p>footer</p>
</footer>
</datagrid>
And I would like to get the inner HTML and parse it on my own.
directive('datagrid', function () {
return {
restrict: 'E',
templateUrl: 'datagrid.htm',
scope: true,
transclude: true,
link: function ($scope, $el, $attr) {
// get inner HTML, separate header and footer HTML to the variables
// and add that HTML later in the template
}
};
});
My template:
<script type='text/ng-template' id='datagrid.htm'>
<table class="datagrid table table-hover table-condensed table-striped">
<thead>
<tr class="top-actions-container">
<!-- INJECT HEADER HTML -->
<th></th>
</tr>
</thead>
<tbody>
<tr>
<!-- RESULTS -->
<td></td>
</tr>
</tbody>
<tfoot>
<tr>
<!-- INJECT FOOTER HTML -->
<td></td>
</tr>
</tfoot>
</table>
</script>
I'm new to the Angular so I'm open to other suggestions. If that's possible is this a good way to do it?
template: function (tElement) { return 'template-string'; }, withtElementgiving you access to the unparsed html, and work from there.<p>{{header}}</p>and let angular do the compiling?