title: How to assign a return value of function to local variable?
body: <p>I need to assign a return value of function to a local variable using Type Script. Below I have explained it clearly:</p>
  
  <pre><code>getdetail1(store){              
      let Cust_id=this.sharedata.latus_lead.m_type
      let url="http:domain.com"
      console.log(url);
      let res;
      this.loginservice.leaddata = null;
      this.loginservice.getdetails(url).then(data=&gt;{
          let lead=data;
          this.details=lead[0];
          res=lead[0];                          
      });
      return res;
  }
  </code></pre>
  
  <p>And calling it like this:</p>
  
  <pre><code>let res = this.getdetail1(store);
  </code></pre>
  
  <p>see this is my login service code</p>
  
  <pre><code>getdetails(query){
         if (this.leaddata) {
          // already loaded data  
          console.log("already data loaded lead") ;
          return Promise.resolve(this.leaddata);
        }
      // don't have the data yet
      return new Promise(resolve =&gt; {
        // We're using Angular HTTP provider to request the data,
        // then on the response, it'll map the JSON data to a parsed JS object.
        // Next, we process the data and resolve the promise with the new data.
          this.http.get(query)
          .map(res =&gt; res.json())
          .subscribe(data =&gt; {
            // we've got back the raw data, now generate the core schedule data
            // and save the data for later reference
            this.leaddata = data;
            resolve(this.leaddata);
          });
      });
  
    }
  </code></pre>
  
  <p>here i handle promise </p>