Ich bin neu in Typoskript. Ich habe eine ID nach der Post-Funktion generiert. Jetzt mit dem _id generiert in post, mit dem ich muss PUT-Funktion für Play-Pause aufrufen, wenn Play Pause-Taste aufgerufen wird Antwort muss auf Server gehen. Ich bin hier, um meinen Code beider ts und API-Service teilen,Wie Antwortdaten als Variable in Typoskript/angular2 gespeichert werden
API-Code für 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: Diese für POST-Funktion ist
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!');
});
Diese für PUT ist Funktion:
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;
}
getröstet Ausgang:
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"
von wo aus Sie rufen 'edit f Salbung? – Sravan
erhalten Sie 'console.log (this.updateId);' als undefined – Sravan
Nein, ich habe das _id jetzt, wenn ich Play/Pause-Taste drücken – Bhrungarajni