Angular 2,递归函数不更新视图

时间:2016-08-19 18:41:26

标签: angular

我有这个递归函数,它调用一个服务来生成和HTTP请求并返回true或false。如果是的话,我将一个字符串推入this.data数组。然后,视图使用this.data来显示列表。

问题是,视图没有自动更新。有没有办法以编程方式刷新视图?还是比这简单?

非常感谢

JT

checkForFile(dateToday: Date, fileListArray: Array<string>, numberOfFilesToCheck: number) {

        // create the filename to search for
        let dateYesterday: Date = this.createDateForYesterday(dateToday);
        let filenameYesterday = this.createFilenameForDate(dateYesterday) + '_activities.csv';
        this.serverDataService.fileExists(filenameYesterday)
            .toPromise()
            .then((data) => {  // the callback where it all happens
                if (data === true) {
                    this.data.push(filenameYesterday);
                }

                // recurse this method until the array is full.
                if (this.data.length < numberOfFilesToCheck) {
                    this.checkForFile(dateYesterday, fileListArray, numberOfFilesToCheck, callCount);
                } else {
                    return;
                }
            });

    }

0 个答案:

没有答案