angular - 变量值未在打字稿中更新
问题描述
export class Test implements OnInit {
getRoleTypeValuesArray:any = [];
array = [];
constructor(private ls: myService) {}
ngOnInit() {
this.ls.testApi().subscribe(y => {
this.getRoleTypeValues = y;
this.getRoleTypeValues.map(y=>{
var obj = { value: y.id, label: y.roleName }
this.getRoleTypeValuesArray.push(obj);
});
this.array = this.getRoleTypeValuesArray;
console.log("test1:",this.array);
});
console.log("test2:",this.array);
}
}
我在控制台中获取值test1
,但不是在test2
控制台之外。这段代码有什么问题?
解决方案
推荐阅读
- angular - 在 Angular 6+ httpClient 中,哪个响应状态代码会出现 catchError?
- c - 当 ADC 为 12 位时,DMA 为何提供 16 位值?
- ethereum - 如何在 Solidity 中管理大循环?
- angular - 带有 {{responseType: 'text}} 的 Angular http.get 错误
- android - 如何将用户加入到在 twilio 中使用 android 创建的频道
- python - 如何过滤数据框以获取在用户定义集中具有列值的行
- c# - Windows ML 学习模型可以通过 UWP 之外的 C# 访问吗?
- java - Jsoup 无法获取带有嵌套标签的外部 HTML
- blockchain - 解释文档中的tendermint 死锁
- r - 如何在包中使用 rlang 运算符?