ERROR TypeError:无法读取属性'然后'角度4中数据表的重新渲染函数中未定义的

时间:2017-11-19 06:49:43

标签: angular datatables

我正在以角度4实现jquery数据表。我通过搜索日期范围来填充表格。所以我需要在每次搜索之前销毁数据表。

  

但是这个功能" rerender()"抛出此错误:ERROR TypeError:   无法阅读财产'然后'未定义的

  rerender():void {
    this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
        // Destroy the table first
        dtInstance.destroy();
        // Call the dtTrigger to rerender again
        this.dtTrigger.next();
    })
}

完整代码:

 export class vendorTransactionComponent implements OnInit {

        @ViewChild(DataTableDirective)
        dtElement: DataTableDirective;
        dtOptions: any = {};
        dtTrigger: Subject<any> = new Subject();

        Vendors: any[];
        data: any[];
        fromDate: Date = new Date();
        toDate: Date = new Date();
        VendorId: number = 1;
        ClientId: number;
        items = new Array;
        itemCount = 0;
        searchkey: any;
        IsTableVisible: boolean = false;
        IsLoadingDivVisible: boolean = false;
        itemLimit = 10;
        vendortransactionList: any[] = [];
        constructor(private vendortrans_serv: vendorTransactionServices) {
            this.ClientId = ConstantData.ClientID;
            this.vendortrans_serv.GetAllVendor().subscribe(data => {
                this.Vendors = data;
            });

        }
        ngOnInit(): void {
            this.dtOptions = {
                pagingType: 'full_numbers',
                //pageLength: 2,
                responsive: true,
            };

        }

        rerender():void {
            this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
                // Destroy the table first
                dtInstance.destroy();
                // Call the dtTrigger to rerender again
                this.dtTrigger.next();
            })
        }

        GetVendortransaction() {
            this.vendortransactionList = [];
            this.IsTableVisible = false;
            this.IsLoadingDivVisible = true;
            this.rerender();
            this.vendortrans_serv.GetVendortransactions(this.fromDate.toDateString(), this.toDate.toDateString(), this.ClientId, this.VendorId)
                .subscribe(data => {
                    if (data.length > 0) {
                        this.vendortransactionList = data;
                        this.IsTableVisible = true;
                        // this.dtTrigger.next();
                    }
                    this.IsLoadingDivVisible = false;
                });
        }
    }

我正在关注以下文章 http://l-lin.github.io/angular-datatables/#/advanced/rerender

0 个答案:

没有答案