【问题标题】:ERROR TypeError: Cannot read property 'aDataSort' of undefined - ANGULAR 8错误类型错误:无法读取未定义的属性“aDataSort”-角度 8
【发布时间】:2021-01-10 19:23:25
【问题描述】:

希望您能帮我纠正数据表中的“aDataSort”错误。

core.js:6014 ERROR TypeError: Cannot read property 'aDataSort' of undefined
at _fnSortFlatten (jquery.dataTables.js:5928)
at _fnSortingClasses (jquery.dataTables.js:6266)
at loadedInit (jquery.dataTables.js:1208)
at HTMLTableElement.<anonymous> (jquery.dataTables.js:1306)
at Function.each (jquery.js:381)
at jQuery.fn.init.each (jquery.js:203)
at jQuery.fn.init.DataTable [as dataTable] (jquery.dataTables.js:869)
at jQuery.fn.init.$.fn.DataTable (jquery.dataTables.js:15210)
at angular-datatables.directive.js:51
at ZoneDelegate.invokeTask (zone-evergreen.js:391)

在我看来,html中的表格要求表格具有

。 但是当表没有任何记录时,我会用“如果”隐藏它。
<div *ngIf="programaciones?.length==0" class="alert alert-info">
        There is no record in the database!
    </div>

    <div class="table-responsive"  >
    <table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="row-border hover">
        <thead *ngIf="programaciones?.length>0">
            <tr >
                <th>Id</th>
                <th>Consultorio</th>
                <th>Usuario</th>
                <th>Fecha</th>
                <th>Hora</th>
                <th>Num. Turno</th>
                <th>Editar</th>
                <th>Eliminar</th>
            </tr>
        </thead>
        <tbody >
             <tr *ngFor="let programacion of programaciones" >
                <td>{{programacion.pro_codigo}}</td>
                <td>{{programacion.consultorio.con_nombre}}</td>

我该如何纠正这个错误,或者在没有记录时有其他方法可以隐藏表格。

【问题讨论】:

标签: javascript java angular spring-boot datatables


【解决方案1】:

如何添加 display: none/hidden 而不是使用 ngIf

类似这样的:

[ngStyle]="programaciones?.length>0 : {'display': 'block'} ? {'display': 'none'}

【讨论】:

  • 我创建了一个布尔变量 vTable 来测试,但我无法隐藏表格。 >component.ts 私有 vTable : boolean = false; >html
  • 哦,对不起。问题在于您的 {'display': 'hidden/none'}。 Display 可以取 hidden、none 或 block 的值,因此您应该只使用其中之一,例如 {'display': 'none'}。另请查看stackoverflow.com/questions/133051/…
  • 我已经可以做到了,我用'none'做到了。非常感谢您对我的帮助。
猜你喜欢
相关资源
最近更新 更多
热门标签