What’s the difference/incompatibility between ng-model and ng-value?

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.

Leave a Comment