在尝试重新分配属性时未定义

问题描述 投票:1回答:1

我有此代码:

this.applicationService.getApplications(id).then(data => {
        console.log(data);
        forIn(GroupOrder,
            (value, key) => {
            if (data.hasOwnProperty(value)) {
                let applicationGroup = {} as ApplicationGroupInterface;
                applicationGroup.count = 2;
                applicationGroup.applicationData = data[value];
                this.applications.push(applicationGroup);
            }
        });
        console.log(this.applications);
    });

我在this.applications之类的组件的开头声明了public applications。但是我在控制台ERROR Error: "Uncaught (in promise): TypeError: this.applications is undefined中收到错误,第一个控制台日志有效,我在data中有数据。请帮我。提前谢谢。

angular typescript typescript2.0
1个回答
0
投票

要将项目推入数组,首先需要对其进行初始化。您可以尝试分配一个空数组

设置:

public applications : Array<any> = [] 
© www.soinside.com 2019 - 2024. All rights reserved.