ng-show在datatables列中不起作用 [英] ng-show not working in datatables columns
问题描述
我正在使用数据表创建一个有角度的表.我使用了作用域中的一个值,并将该值与接收到的数据进行比较.
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"}]
当我加载数据时,两个按钮都出现在行-列中,并且该条件仅在我单击ng-click操作时才适用.
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?
推荐答案
显然,angular不了解dataTables注入的HTML.在这种情况下,我使用 $ compile
在 drawCallback
中绘制的内容:
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))
}
其中 #tableId
是表的 id
.但是总的来说,这有点混乱,恕我直言.当我需要附加到dataTables行或列的特定角度指令时,可以使用 datatable ="ng"
渲染角度方式.速度较慢,但更干净和可维护.
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.
这篇关于ng-show在datatables列中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!