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

88
Views
Connecting it with Ngmodel using nested objects in Angular

person.model.ts page;

export class Person {
    name: string;
    email: string;
    desc: string;
    adres: Address;
}

export class Address {
    city: string;
    disticy: string;
    postCode: number;
    country: string;
}

person.component.html page;

...

<div class="bg-secondary container"> {{ jsonPerson }} </div>

...

<input [(ngModel)]="newPerson.adres.city" name="city" type="text" id="city" placeholder="Şehir" class="form-control">

...

form.component.ts page;

...

public newPerson: Person = new Person();

get jsonPerson() {
  return JSON.stringify(this.newPerson) 
}

...

The problem is; I want to use my address information as an object. And this is how I used it. But when I bind to my html page as [(ngModel)]="newPerson.address.city" I get an error. That is, how can I reach the Address object inside the Person object and get a successful output.

Information: person.model.ts is not my data source. I distribute my data to the necessary pages via person.service.ts. so there is no database

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

0

You need to initialize it.

export class Person {
    adres: Address = new Address();
}

or

export class Person {
    adres: Address;
    constructor() {
      this.adres = new Address();
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

@Furkan just keep in mind that:

Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in a future version of Angular.

Now deprecated: <input [formControl]="control" [(ngModel)]="value">

https://angular.io/guide/deprecations#ngmodel-reactive

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!