i need to assign the subscribed data to a variable and display it in html but it always gives me "undefined"
i have tried to move the function to the constructor but always the same problem!
export class EspacePartenaireComponent implements OnInit {
public result: any;
constructor(private partenaireService: EspacePartenaireService) {
this.getServices();
console.log(this.result);
}
getServices() {
this.partenaireService.myServices().subscribe(data => {
this.result = data;
console.log(data)
});
}
ngOnInit() {}
}
the console.log inside subscribe shows the data but the one inside the constructor doesn't, i expect to see the data since i am assigning it to a global variable!