Angular 2/4:在订阅中设置后获取值

时间:2017-08-17 09:29:19

标签: angular typescript

如何获得" 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
      }

如何获取订阅之外的值?

0 个答案:

没有答案