How does (ngModel) syntax explicitly work?

60 Views Asked by At

I am trying to understand how ngModel directives work in Angular. I ran into this simple line of code, which makes absolutely no sense to me and I'll explain why :

<input (ngModel)="userName" />

For me, the "(ngModel)" syntax means we are listening to any Output event named "ngModel". I am saying this because this is what I learned from "@Output" component communications in Angular docs. That being said, with "()" syntax, we should normally give the JavaScript instructions to apply whenever the output emits an event named "ngModel". So we should normally write (ngModel)="do something()" and not (ngModel)="userName"

So again what I don't understand here is (ngModel)="userName", userName is not an instruction, it is a field in my component class: it doesn't make sense to me... Besides how ngModel directive sets its own @Input ngModel attribute since we don't use "[]" syntax, which means, the @Input doesn't keep track of the changes of our input

0

There are 0 best solutions below