title: How to store response data as variable in typescript/ angular2
body: <p>I am new to typescript. I have got an id generated after post function. Now by using that _id generated in post,using that i must call PUT function for play pause, when play pause button is called response must go to server. I am here by sharing my code of both ts and API service,</p>
  
  <p>API code for PUT:</p>
  
  <pre><code>    edit(updateId) {
    console.log(updateId);
    let authToken = JSON.parse(localStorage.getItem('authToken'));
    var company_id = JSON.parse(localStorage.getItem('company_id'));
    var queries = "?authToken=" + authToken + "&amp;&amp;_id="+ company_id +"&amp;&amp;view_id=2";
   return this.http.put(urlBase + '/timerEntry/' + updateId ,options)
                    .map(this.extractData)
                    .catch(this.handleError);
  }
  </code></pre>
  
  <p>TS code:
  This is for POST function </p>
  
  <pre><code>this.ApiService
   .addtimerEntries(new_task)
                .subscribe(
                  entry  =&gt; {
                   console.log(entry)
                    this.todays.today.push(entry.data[0]);
                    this.updateId = entry.data[0]._id;
                   console.log(this.updateId);
                this.toasterService.pop('success', 'Entry added 
                 successfully');
                this.newTask.hide();
              },
            error =&gt; {
            this.toasterService.pop('error', 'Something went wrong!');
          });
  </code></pre>
  
  <p>This is for PUT function:</p>
  
  <pre><code> playTimer() {
       this.timerService.playTimer();
        this.playDiv = true;
        console.log(this.updateId);
        if (this.updateId){ 
      this.ApiService
             .edit( this.updateId)
             .subscribe(
               user =&gt; {
                 console.log(user);
                 this.ApiService
                            .getEntries(this.workEmail)
                            .subscribe(
                              entries  =&gt; {
                                console.log(entries);
                                this.entries = entries;
                        this.toasterService.pop('success', 'updated successfully');},
                      error =&gt; {
                        //console.log(error);
                      });
               },
               error =&gt; {
                  this.toasterService.pop('error', 'Something went wrong!');
               });
      }
      }
      pauseTimer() {
       this.timerService.pauseTimer();
        this.playDiv = false;
      }
  </code></pre>
  
  <p>Consoled Output:</p>
  
  <pre><code>data:Array(1)
  0:Object
  category_id:1
  client_id:15
  company_id:4
  department_id:26
  entry_type:"checkin_entry"
  project_id:7
  subcategories:Array(1)
  times:Array(1)
  workEmail:"test3@test.com"
  _id:"59362522325a5a0786f661b3" 
  </code></pre>