0
I’m using a template I bought made in Angular, but not everything in Angular has a lot in jQuery.
I’m using jQuery’s Datatable (because it’s already native to the template, it has all the css ready and even is already searching the data and paging), but I need some actions in some elements that I need (want) to be processed by angular. How to mark a checkbox for example.
I am using the fnRowCallback from Datatable to handle html. In the example below I would like to change the checkbox state (html generated by the plugin in jQuery) the data to be sent to the changePropertyEnabled method (Angular component method)
...,
fnRowCallback: function (nRow, aData, iDisplayIndex) {
const mDataEnabled = '<label class="ui-switch switch-icon">' +
'<input type="checkbox" (change)="changePropertyEnabled(1, false)">' +
'<span></span>' +
'</label>';
const mDataRemoveIcon = '<a class="text-muted font-16" href="javascript:;"><i class="ti-trash"></i></a>';
//
$('td:eq(0)', nRow).html(mDataEnabled);
$('td:eq(6)', nRow).html(mDataRemoveIcon);
return nRow;
},
...
changePropertyEnabled(id: number, enabled: boolean) {
alert('Hello World');
}
Is your HTML generating normally? Why your call with
(change)="changePropertyEnabled(1, false)"
is correct. And there is some specific reason that you are dynamically generating this HTML byfunction
? You could create it normally and use a*NgIf
on the call of the same.– Patrick Lima
It is generating yes, but the change does not work. I just found a solution now little, but I do not know if it is the best way. I used static html just to test even.
– Sileno Brito
Because then, maybe this HTML that he manages Angular is not able to handle in the node that he created, consequently not treating the
change
but that’s an assumption. Maybe generating it without being static is a good try.– Patrick Lima
@Patricklima is just that.
– Sileno Brito