How do i call the service to create the object first to avoid the undefined error ? The service this just return this.httpclient.get("serviceUrl") ts file
export class AboutmeComponent implements OnInit {
personalInformation: Object;
constructor(private portfolioService: PortfolioService) {
this.getPersonalInformation();
}
ngOnInit() {
}
getPersonalInformation(){
return this.portfolioService.getPersonalInformation().subscribe(data=>{
console.log(data);
this.personalInformation = data;
});
}
}
html file
<p>aboutme works!</p>
<mat-grid-list cols=4>
<mat-grid-tile [colspan]=3>
</mat-grid-tile>
<mat-grid-tile [colspan]=1>
<img [src]="personalInformation.profilePhotoUrl" alt="">
</mat-grid-tile>
</mat-grid-list>
error
Cannot read property 'profilePhotoUrl' of undefined