gpt4 book ai didi

javascript - 返回未定义的数组 - 依赖注入(inject)? Angular/ typescript

转载 作者:行者123 更新时间:2023-11-30 09:19:54 24 4
gpt4 key购买 nike

我分配一个从端点接收的数组数据。

我尝试在另一个文件中调用这个数组,但它不喜欢!我的 subsidiaryNames 数组控制台正确。

我的第一个文件:

export class EngagementService {
public orgSubSidNames = [];


let subsidiaryNames = []
data.forEach(sub => {
console.log(sub.SubsidiaryName)
subsidiaryNames.push(sub.SubsidiaryName)
})
subsidiaryNames = subsidiaryNames.filter(this.onlyUnique);
console.log('subsidiary name array' + subsidiaryNames)
this.orgSubSidNames = subsidiaryNames;

// This is just a sample script. Paste your real code (javascript or HTML) here.

if ('this_is' == /an_example/) {
of_beautifier();
} else {
var a = b ? (c % d) : e[f];
}

第二个文件:

export class EngagementFilterComponent implements OnInit {
public subSidNameArray: EngagementService;


updateSub(data) {
console.log(data);
console.log('attempting to print the subsid array' + this.subSidNameArray.orgSubSidNames)
}

我得到错误:

 Cannot read property 'orgSubSidNames' of undefined

最佳答案

您永远不会设置属性的值 public subSidNameArray: EngagementService;

关于javascript - 返回未定义的数组 - 依赖注入(inject)? Angular/ typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com