whats the difference between ng-model and ng-value

Divya MV提出了一个问题:whats the difference between ng-model and ng-value,或许与您遇到的问题类似。

回答者JcT给出了该问题的处理方式:

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.

希望本文对你有帮助,欢迎支持JavaScript中文网