Search code examples
angulartypescriptconventions

This in ngModel


I have noticed that in my angular application there are usages of

[(ngModel)]="this.properties.offerValue" and [(ngModel)]="properties.offerValue"

Both of them seem to work the same, my curiosity raised a question, is there any difference, and which is the correct usage.


Solution

  • Angular 2+ supports both options for two way data binding. If you pass this refers to host component class. If not passed, that will internally refer to same component class.

    Preferred way :

    [(ngModel)]="properties.offerValue"