javascript - TypesScript: unable to read a property of an object even though it's there -
i'm trying create body , send url backend stores content objects. when use const body = json.stringify(content); doesn't read property file.
here service code:
addmessage(content: content) { console.log("service:", content); // file property in content object sent const body = json.stringify(content); // file property missing here console.log("body:", body); const headers = new headers({'content-type': 'application/json'}); const token = localstorage.getitem('token') ? '?token=' + localstorage.getitem('token') : ''; return this.http.post('http://localhost:3000/content' + token, body, {headers: headers}) .map((response: response) => { const result = response.json(); const newcontent = new content( result.obj.name, result.obj.user.firstname, result.obj._id, result.obj.user._id, ); this.contents.push(newcontent); return newcontent; }) .catch((error: response) => { this.errorservice.handleerror(error.json()); return observable.throw(error.json()); }); } here's console:
you can see file in content doesn't appear in body. tried doing json.parse(json.stringify(content)); , surprise, content.file undefined. idea could've went wrong?
thank you!
have tried json.stringify(json.parse(content)); ?
first need parse json, , once parsed stringify it.
let me know if helps you! :d

Comments
Post a Comment