For performance resins I am using a JQuery DataTable inside my controller without attaching it to the model. I need to be able to compile the directive inside the controller and return the html to the DataTable's render function.
Syntax Error: Token 'Object' is unexpected, expecting []] at column 9 of the expression [[object Object]] starting at [Object]].
Controller:
self.icons = ['icon-remove', 'icon-file', 'icon-rocket'];
self.rocketOpt = ['Launch', 'Individual', 'Group'];
self.removeOpt = ['Delete'];
self.scanOpt = ['Individual', 'View'];
jQuery('tbl').DataTable({
data: self.tbl,
columns: [
{
data: 'action',
order: [],
render: function (data, type, full, meta) {
var html = '';
// different items get different icons
if (full.name.search(/Announce/) !== -1) {
html = getBtnHtml(self.icon[0], self.removeOpt);
} else if (full.name.search(/[fF]ile/) !== -1) {
html = getBtnHtml(self.icon[1], self.scanOpt);
} else {
html = getBtnHtml(self.icon[2], self.rocketOpt);
}
return html;
},....
function getBtnHtml(icon, options){
// Not working ?????????????????????
var html = '<action-buttons id="remove" icons="' + icon + '" options="' + options + '"></action-buttons>';
return ($compile(html)($scope)[0]);
}
Directive:
var actionButtons = function () {
return {
restrict: 'E',
templateUrl: 'partials/actionButtons.html',
scope: {
icons: '@',
options: '@'
}
};
};
HTML Template:
<div class="RUIFW-btn-group bg-danger">
<button class="RUIFW-btn">
<span class="{{ icons }}"/>
</button>
<a data-toggle="dropdown" class="RUIFW-btn dropdown-toggle">
<span class="sr-only">More Options</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li ng-repeat="option in options">
<a href="#/">{{ option }}</a>
</li>
</ul>
</div>