I have a service which gets data from API : https://jsonplaceholder.typicode.com/posts/1
but i can not store data in variable
Code : Service.ts
public urlServer : string = "https://jsonplaceholder.typicode.com/posts/1";
public getAllProjectsFromAPI() : Observable<any> {
return this.http.get( this.urlServer, { responseType: 'json' } );
}
Component.ts
constructor( private projects : ProjetsService ) { }
ngOnInit() {
this.projects.getAllProjectsFromAPI().subscribe( data => this.test = JSON.stringify( data ) );
console.log( this.test );
}
I try to console test var and i get undefined