angular2 - 2 ways of getting value from ngmodel



There are 2 ways you can get value from ngModel. In this example, we have an input and whenever you change the text, it will always keeps your value updated.

#1. via Get / Set method

The first method uses, get and set to get value from model. Whenever a value is set, it triggers a custom event which parent class can listen to.



#2 via ngModelChanged Event -

If you decided not to do it that way, you can use ngModelChanged event to get value  as illustrated in codes below :



#3 Listening to onkeydown events - which will not be discussed here. :)

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm