What is ngModel in Angular?
ngModel provides us the mechanism to sync input data/data from any source (like Web API, Database) from HTML control element to the component class.
Understand this in the very easy way:
Suppose you have a user class named with User as following:
[ngModel]="user.email" is the syntax for one-way binding, while,
[(ngModel)]="user.email" is for two-way binding, and the syntax is compound from
[ngModel]="user.email" and (ngModelChange)="user.email = $event"
If you only need to pass the model, use the first one. If your model needs to listen to change events (e.g. when input field value changes), use the second one.
It's quite simple [] => component to template () => template to component [(ngModel)] is a contracted form of [ngModel]="currentHero.name" (ngModelChange)="currentHero.name=$event">
Understand this in the very easy way:
Suppose you have a user class named with User as following:
export class User {
id: number;
email: string;
constructor(values: Object = {}) {
//Constructor initialization
Object.assign(this, values);
}
}
And in HTML, you have a textbox for binding email property of the user class.
For simplicity, we will call User class to "U" and textbox control to "T".
So here are the following definitions:
ngModel provides the way of binding data from U to T and/or vice-versa.
[ngModel]="user.email" is the syntax for one-way binding, while,
[(ngModel)]="user.email" is for two-way binding, and the syntax is compound from
[ngModel]="user.email" and (ngModelChange)="user.email = $event"
If you only need to pass the model, use the first one. If your model needs to listen to change events (e.g. when input field value changes), use the second one.
ReplyDeleteNice Blog
Thanks sharing for useful information
Tempo Traveller in Amritsar
Tempo Traveller Price
Tempo Traveller Seats
Tempo Traveller Rate in Amritsar
Tempo Traveller on Rent
Tempo Traveller 9 Seater
Tempo Traveller 12 Seater
Tempo Traveller 14 Seater
Tempo Traveller 15 Seater
Tempo Traveller 17 Seater
Tempo Traveller 9 Seater Rent Per KM
Tempo Traveller 12 Seater Rent Per KM
Tempo Traveller 14 Seater Rent Per KM
Tempo Traveller 15 Seater Rent Per KM
Tempo Traveller 17 Seater Rent Per KM
LuxuryTempo Traveller in Amritsar
Tempo Traveller Rental in Amritsar
Tempo Traveller Hire in Amritsar
Tempo Traveller Bookung in Amritsar
Tempo Traveller Service in Amritsar
9 Seater Tempo Traveller in Amritsar
12 Seater Tempo Traveller in Amritsar
14 SeaterTempo Traveller in Amritsar
15 Seater Tempo Traveller in Amritsar
17 Seater Tempo Traveller in Amritsar
Very interesting post...
ReplyDeleteAbout - What is ngModel in Angular?
Important Things To Check For Before You Hire C# Developers
Hire C# developers
Free APPS APK APPS
ReplyDeleteFor New Updated Visit New Tips
ReplyDeleteThank you for giving this useful information in this article. It's a fantastic article. I'll be waiting for your next update. I also have some useful information about the Best Custom Software Development Company in India, which I believe will be of great use to you.
ReplyDeleteFind WordPress Developers in Delhi that are available for hire for your job. Outsource your WordPress jobs to a Freelancer and save.
ReplyDelete