Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is ngModel without [] and ()?

what is ngModel without brackets and parentheses and when to use it?

<input name="name" ngModel>

I know [ngModel] is syntax for one-way bindning and [(ngModel)] is two-way bindning but what does it mean when you write without any brackets and parentheses?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

NgModel is just a directive.
From Angular documentation:

Creates a FormControl instance from a domain model and binds it to a
form control element.

If you put it into HTML element, it just brings all methods of this class to the element. Thus means you can use it with your needs, for example get change event – (ngModelChange).

Small example:

<input (ngModelChange)="onChange($event)" ngModel />

This input has no initial value, but will emit event on change.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading