skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. <input name="name" [(ngModel)]="propertyName">

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search