When trying to access an object assigned by a function in ngOnInit, I am encountering an issue where the console log is showing it as undefined. Oddly enough, the same variable is accessible inside the LoadSelCompanies subscription block:
export class dealComponent implements OnInit {
selfcompanies;
self;
dealForm: FormGroup;
constructor(private userService: UserService) { }
ngOnInit() {
this.AddControls();
this.LoadSelCompanies();
console.log(this.selfcompanies);
}
LoadSelCompanies() {
this.userService.LoadCompanyInfo().subscribe(data => {
this.selfcompanies = data;
console.log(data);
console.log(this.selfcompanies);
});
}
I am currently at a loss and seeking guidance on this matter.