ng-show not working in datatables columns

不打扰是莪最后的温柔 提交于 2019-12-11 05:54:05

问题


I am creating a table in angular using datatables. I've use a value from the scope and I compare this value with the data received.

"columns": [{ data: null, render: function ( data, type, row ) {
var roleid =angular.element('#TextkeysController').scope().currentRole;
return '<p ng-show="'+data.id+' == '+roleid+'" class="btn btn-success btn-xs disabled" value="connected" >connected</p><p ng-show="'+data.id+' != '+roleid+'" class="btn btn-danger btn-xs" value="notConnected" ng-click="connectRole(\''+data.id+'\',\''+data.name+'\')">Not connected</p>';
}, name: 'connect', "className":"center"}]

When I load the data both button appear in the row - column and the condition only apply when I click in a ng-click action.

Could someone help me to know why this happen?


回答1:


Obviously angular is not aware of the HTML injected by dataTables. In this cases I use to $compile the rendered content in a drawCallback :

withOption('drawCallback', function() {
   $scope.$apply($compile(angular.element('#tableId'))($scope))
}

where #tableId is the id of your table. But in general this is a little bit messed up, imho. When I need specific angular directives attached to dataTables rows or columns I render the angular way with datatable="ng". Slower but more clean and maintainable.



来源:https://stackoverflow.com/questions/38657552/ng-show-not-working-in-datatables-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!