如何获得" subscribe"中设置的值?在它之外:
MyComponent.ts
getLabelTypeOfDemandByCode(code: string) {
const label;
this.adminService.getLabelByCode(code).subscribe(
labelByCode => {
label = labelByCode.label;
localStorage.setItem(code, JSON.stringify(labelByCode.label));
});
// Here when I check the value of label it is null
console.log(label); // ==> null
// Or when I try to get value of local storage
console.log(JSON.parse(localStorage.getItem("ABI")); // it is null
}
如何获取订阅之外的值?