Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Angular ngOnInit the object property is always undefined despite the the object has value

I have an angular project and currently I am trying to set a reactive form values on ngOnInit method. I get the data with http call from a backend server. In the ngOnInit method I can monitor data on browser console; but the properties of the data object are always undefined despite the objects have this properties with proper values.

Here are the interested code blocks:

 ngOnInit(): void {
    this.clientService.getClientBusinessYearDetails(this.clientBusinessYearId).subscribe(data  => {
         console.warn(data);
         console.warn(data.clientName);
         this.organizationDetailsFormValues.contactPerson = data?.clientName;
         this.clientProfileForm.controls.organizaionDetails.setValue(this.organizationDetailsFormValues);
    });
  }

You can see the details on the screen shot of browser console, the data object has a proper clientName property but it is showing up null when I try to using it in somewhere else: enter image description here

The form that I want to set it's value is a reactive form which has several child form groups from inner components. I have simplified the ngOnInit method on purpose to read it easier. when I set a control of form as hardcoded it is working and the value showing up on form but when I set the control's value as above it is not showing up because the property value is undefined.

Any Idea ? I have checked this question which quite similar but my goal is not showing the property's value on console.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

data is an array, just assign values of first element of this array.

 ngOnInit(): void {
    this.clientService.getClientBusinessYearDetails(this.clientBusinessYearId).subscribe(data  => {
         console.warn(data);
         console.warn(data[0].clientName);
         this.organizationDetailsFormValues.contactPerson = data[0]?.clientName;
         this.clientProfileForm.controls.organizaionDetails.setValue(this.organizationDetailsFormValues);
    });
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!