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,
API code for PUT:
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 + "&&_id="+ company_id +"&&view_id=2";
return this.http.put(urlBase + '/timerEntry/' + updateId ,options)
.map(this.extractData)
.catch(this.handleError);
}
TS code: This is for POST function
this.ApiService
.addtimerEntries(new_task)
.subscribe(
entry => {
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 => {
this.toasterService.pop('error', 'Something went wrong!');
});
This is for PUT function:
playTimer() {
this.timerService.playTimer();
this.playDiv = true;
console.log(this.updateId);
if (this.updateId){
this.ApiService
.edit( this.updateId)
.subscribe(
user => {
console.log(user);
this.ApiService
.getEntries(this.workEmail)
.subscribe(
entries => {
console.log(entries);
this.entries = entries;
this.toasterService.pop('success', 'updated successfully');},
error => {
//console.log(error);
});
},
error => {
this.toasterService.pop('error', 'Something went wrong!');
});
}
}
pauseTimer() {
this.timerService.pauseTimer();
this.playDiv = false;
}
Consoled Output:
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:"[email protected]"
_id:"59362522325a5a0786f661b3"
edit function?console.log(this.updateId);as undefined