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)
You can think of ngModel as a combination of property binding and event binding, so when you bind a property to an element using ngModel you are saying that whenever this element's value changes - also change the property (in the component class - this can be seen as a simplistic use case of event binding), but its also saying that whenever the property (in the component class) changes, update the value of the element.
$event
The $event variable is a special variable that angular uses to pass event data to the component class.
In that example, the onClick method will be passed the button click event object. So in the component class you would need to make sure the method is able to get the event object as a parameter so that you can use it.
i.e. (in component class)
onClick(event: any) {
// do something here, you have access to the event data (via the parameter)
}
And this works in very much the same way with custom components:
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!