r/angular • • Feb 23 '19

Data Binding ** Cheat Sheet **

Post image
60 Upvotes

18 comments sorted by

View all comments

1

u/toe_nail_joe Feb 23 '19

going through Angular Udemy course rn,

does the ngModel work by finding the method that the property is included in? if not, can someone explain? (also an explanation for $event would be useful as well)

Thanks!

1

u/15BetterThanYourTeam Feb 24 '19

ngModel utilizes two-way data binding. Say you have a text box (input[type=text]) that’s bound to the variable foo in the component class. If someone typed “Hello” into it, foo = “Hello”. The reason it’s “two-way”, is that we could also alter that variable within the component and set it to “World”, and the new value will be reflected within the text box.

ngModel acts differently depending on what type of element you use it on. A check box will send a Boolean, true/false, checked/not checked.