title: how to wait for asynchronous data coming from a subscription
body: <p>So I'm trying to wait subscribe to a data coming from a local storage service, but the data I get from the local storage is sometimes late and the .Uid is not defined</p>
  
  <pre><code>constructor(private route: ActivatedRoute,
              private cp: CommerceProvider,
              protected localStorage: LocalStorage) {
    this.localStorage.getItem('castra').subscribe((data) =&gt; {
      this.uid = data.uid;
      console.log(data);
      this.getCastraProfile();
  
    })
  }
  
  ngOnInit() {
    let id = parseInt(this.route.snapshot.paramMap.get('id'));
    this.castra_id = id;
    this.localStorage.getItem('cart').subscribe((cart) =&gt; {
      if(cart.length == 0){      
        this.localStorage.setItem('castra', { 'uid': this.castra_id 
   }).subscribe(() =&gt; {});
      } 
    }, (error)=&gt; {
      this.localStorage.setItem('cart', []).subscribe(() =&gt; {});
   });
  }
  </code></pre>
  
  <p>so how to wait for this data to come then assign it to the uid variable?</p>