Unable to retrieve values from nested objects in component.html

Hey fellow tech enthusiasts, I'm currently dealing with a complex nested JSON object retrieved from an API. Here's a snippet of the object:

profile : {
    title:"Mr",
    personalInfo:{
       fullNames: "John Doe",
       id: "569"
   }
   Address:{
    line1:"addd one",
    line2:"addd two" 
   }
}

As for my HTML component:

<ion-input placeholder="Full Names" [(ngModel)]="profile.personalInfo.fullNames"  ></ion-input>

Upon compiling the code, I encountered an error message stating

TypeError: Cannot read property 'personalInfo' of undefined

Interestingly, when I access the non-nested title property in my HTML component, everything works fine.

Any insights on how to tackle this issue?

Answer №1

The JSON data appears to be incorrect, have you reviewed it? You seem to have forgotten a comma before the address key

{
  "title": "Mrs",
  "personalInfo": {
    "fullName": "Jane Smith",
    "id": "897"
  },
  "Address": {
    "street1": "123 Main Street",
    "street2": "Apt 4B"
  }
}

Answer №2

Have you saved this data in a global variable that can be accessed by the HTML? It looks like the information is not being stored anywhere, as your binding would normally appear like this:

<input placeholder="Enter Name" [(ngModel)]="data.name"></input>

Make sure to store your response in a global variable named 'response' and access it from within the HTML.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The async validator in Angular will only activate upon submission if the user has made changes to the form

In my angular 10 application, I have implemented a login form with various validation checks for the username and password fields. These validations are carried out using an async validator that is applied to the formgroup containing the username and pass ...

Which is better for posting data via ajax: using JSON.stringify() or default URL encoding?

Is there a specific advantage to using JSON.stringify() when posting a complex object compared to allowing default url encoding with jQuery.ajax? The MVC WebApi I am utilizing is able to handle both types of requests without any issues, so the need to send ...

Develop a JSON array of objects using a Dictionary in C#

I'm really stuck on this issue and I know there must be a simple solution out there that I just haven't discovered yet. My task is to generate an array of objects in JSON, a format that I am quite new to. The desired structure should resemble th ...

Initial compilation of Angular 2 project with lazy-loaded submodules fails to resolve submodules

I'm working on an Angular 2 project (angular cli 1.3.2) that is structured with multiple modules and lazy loading. In my main module, I have the following code to load sub-modules within my router: { path: 'module2', loadChildren: & ...

Troublesome bug in Angular 7: [ngModel] functionality fails to cooperate with mat-select

Having trouble implementing ngModel in the following scenario: Check out the template code below: <mat-select [ngModel]="data.dataObject[0].phase"> <mat-option *ngFor="let phase of possiblePhases" [value]=" ...

An issue has been identified in the node_modules/xterm/typings/xterm.d.ts file at line 10, causing an error with code TS1084. The 'reference' directive syntax used

In my project, I have integrated xterm into Angular5. However, I am encountering an error when trying to run the application. Upon executing ng serve, I am facing the following error: ERROR in node_modules/xterm/typings/xterm.d.ts(10,1): error TS1084: In ...

Transferring a JSON object to a PHP script

I am attempting to send a JSON object with a structure like this: {"service": "AAS1", "sizeTypes":[{"id":"20HU", "value":"1.0"},{"id":"40FB","2.5"}]} Just to note: The sizeTypes array contains a total of approximately 58 items. Upon clicking the submit ...

The immutability of the List in JavaScript and its

I am confused about how the size of an Immutable JS List grows. According to the official documentation example at https://facebook.github.io/immutable-js/docs/#/List/push, pushing something into an immutable js List should automatically increase its size ...

Navigating JSON Data in Groovy Using a Loop: A Handy Guide

Just starting out with Groovy and attempting to mock a service in SoapUI. The task at hand involves loading a text file containing JSON data, and then matching that data to a specific node. Here is what I have attempted so far: def inputFile = new File( ...

Updating MongoDB every 30 seconds using remote JSON data: A step-by-step guide

I'm currently working on parsing remote JSON data and storing it in MongoDB. The JSON data I am dealing with is dynamic, so I want to continuously update MongoDB with this dynamic data every 30 seconds. Here's an example of how I parse the JSON ...

Guide to Conditionally Importing a Module in Angular

I am currently developing a module for Search integration. Instead of directly importing the SearchModule inside my app.module.ts file, I would like to implement a method where an API is called and the SearchModule is imported based on the API response. @N ...

Guide on accessing mobile information and sim card details with Ionic 3 and Cordova on Android devices

Just started using Ionic and I'm looking for guidance on how to retrieve mobile and sim details with Ionic 3 and Cordova for Android. Any help is greatly appreciated in advance! ...

TypeScript does not verify keys within array objects

I am dealing with an issue where my TypeScript does not flag errors when I break an object in an array. The column object is being used for a Knex query. type Test = { id: string; startDate: string; percentDebitCard: number, } const column = { ...

Angular, Observable, and the wonders of debounceTime

I have a function within an Angular 4 project called reload() that can be triggered by other functions, A() and B(), at any given time. I am looking to implement a debounce feature for reload() so that it is only executed after a specified duration (X mill ...

What is the best method for obtaining non-null values for the jsonSerialize interface in PHP?

My class is using the jsonSerialize method in php After implementing the jsonSerialize method, my class returns only non-null variables by utilizing get_object_vars($this). public function JsonSerialize() { $vars = get_object_vars($this); r ...

The release of the Angular App within a webjar is causing problems relating to the baseHref

Currently, I am looking to package my Angular frontend in a webjar so that it can be easily imported via Maven into any Java backend. Successful in this task, I now have a Spring Boot backend with an application.properties file showing: server.servlet.cont ...

Is there a method in Flask to conceal a specific @app.route so that only the application itself can access it? I am concerned about the visibility of my database through a URL in JSON format

Currently, I am working on a FLASK server that utilizes sqlite3, json, axios, and VUEJS. My VueJS frontend communicates with the sqlite3 database through axios. The database is sent using jsonify over @app.route('/api/getdatabase', methods=[&apos ...

Guide on integrating an Excel file into the ag-grid-angular platform

I was looking for the import method, but I couldn't seem to find it. Does anyone have any idea where it is located? Please inform me! ...

converting JSON data fetched from an API into state using setState

My goal is to properly map a JSON response into a state by excluding the first array and only displaying its children. Here is an example of what I have attempted: fetch(api).then((response) => { response.json().then((data) => { data.children. ...

A guide to serializing declarative links using Jersey and Jackson

In my project, I have implemented declarative linking. The configuration for my Jackson mapper is as follows: final ObjectMapper mapper = new ObjectMapper(); mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); mapper.configure(MapperFea ...