As far as i understood ng-model sets the value for that particular element in which the model is been assigned. given that how is ng-value different from ng-model?
There is no difference between ng-model and data-ng-model if you see in terms of AngularJs. Actually, 'data' used as prefix to validate HTML5 validation. So, it is good practice to use data-ng-model , however, you can use ng-model as well. There is no problem in that also.
The NgModel class has the update property with an EventEmitter instance bound to it. This means we can't use (ngModelChange) without ngModel . Whereas the (change) event can be used anywhere, and I've demonstrated that above with the [value] property binding instead.
ngModel usually use for input tags for bind a variable that we can change variable from controller and html page but ngBind use for display a variable in html page and we can change variable just from controller and html just show variable.
Ng-change is a directive in AngularJS which is meant for performing operations when a component value or event is changed. In other words, ng-change directive tells AngularJS what to do when the value of an HTML element changes. An ng-model directive is required by the ng-change directive.
It works in conjunction with ng-model; for radios and selects, it is the value that is set to the ng-model when that item is selected. Use it as an alternative to the 'value' attribute of the element, which will always store a string value to the associated ng-model.
In the context of radio buttons, it allows you to use non-string values. For instance, if you have the radio buttons 'Yes' and 'No' (or equivalent) with values 'true' and 'false' - if you use 'value', the values stored into your ng-model will become strings. If you use 'ng-value', they will remain booleans.
In the context of a select element, however, note that the ng-value will still always be treated as a string. To set non-string values for a select, use ngOptions.
Simple Description
ng-model
$modelValue
(value reside in actual scope) & $viewValue
(value displayed on view).Eg.
<input type="text/checkbox/radio/number/tel/email/url" ng-model="test"/>
ng-value
ng-model
value like input
, select
& textarea
(same can be done by using ng-init
)ng-value
does provide good binding if your are setting ng-model
value through ajax while writing value
attribute doesn't support itradio
& option
tag while creating select
options dynamically.string
value it, it doesn't support object value.HTML
<input [ng-value="string"]> ... </input>
OR
<select ng-model="selected"> <option ng-value="option.value" ng-repeat="option in options"> {{option.name}} </option> </select>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With