基金-dropdown.js
export class FundDropdown{
fundTypes: string[];
fundCategorys: string[];
}
测试组件.ts
export class PrimengTestComponent implements OnInit {
date: Date;
fundDropdown: FundDropdown;
constructor(private fundInfoService: FundInfoService) {
console.log(this.fundDropdown);
console.log(this.fundDropdown.fundTypes.length);//the error occurs in this line
}
ngOnInit(): void {
this.fundDropdown = new FundDropdown();
this.fundInfoService.getFundTypeAndFundCategory().subscribe(
(data) => {
console.log(data);
this.fundDropdown = data;
},
(error) => console.log(error)
);
}
}
fundDropdown 的数据是:
{"fundCategorys":["aaaa"],"fundTypes":["sdf","qwe","agas"]}
FundDropdown 数据来自后台,其类型为 Map<String, List>