1
I’m trying to access a data ID that my API
responds that it is inside an array:
{
"name": <name>
"email": <email>
"token": <token>
"message": 'Token válido.'
"subscriptions": [
{
"id": "<id>", // preciso pegar a id
"startdate": "<startdate>",
"enddate": "<enddate>",
"active": "<active>",
"course": "<course>"
}]
}
I’m saving in the localStorage
cell phone as follows:
ngOnInit() {
this.authloginService.getCourses(this.token, this.course)
.then((result)=> {
localStorage.setItem('subscriptions(id)', result['subscriptions'])
console.log(result['subscriptions']);
});
}
But the console.log
me answers the entire array of subscriptions
;
Here the service:
getCourses(token:string, course:string){
token = encodeURIComponent (localStorage.getItem('token'));
course = encodeURIComponent (course);
var cursos = `token=${token}&course=${course}`;
return this.http.post('https://minhaapi.com.br/api/subscriptions',
cursos , {headers: this.headers}).toPromise();
}
I’m missing in the localStorage
or in the service?
That’s right, thank you very much !
– rzp