javascript - Angularjs 单选按钮

标签 javascript angularjs

当 ng-value 是整数时,我遇到以下问题,而当 ng-value 是字符串时,我遇到以下问题。有谁知道为什么会发生这种情况吗?

<input type="radio" name="grupoRadio" ng-value="1" ng-model="valor" > Certificado de cobertura sin nómina de personal
 <br>
<input type="radio" name="grupoRadio" ng-value='CNC' ng-model="valor" > Certificado de cobertura con nómina de personal completa
 <br>
<input type="radio" name="grupoRadio" ng-value="CNP" ng-model="valor">  Certificado de cobertura con nómina de personal parcial

最佳答案

ng-value用于 scope 中定义的变量,如果你想分配一些静态数据,你需要 value input 的属性喜欢

<input type="radio" name="grupoRadio" value="1" ng-model="valor" > Certificado de cobertura sin nómina de personal
 <br>
<input type="radio" name="grupoRadio" value='CNC' ng-model="valor" > Certificado de cobertura con nómina de personal completa
 <br>
<input type="radio" name="grupoRadio" value="CNP" ng-model="valor">  Certificado de cobertura con nómina de personal parcial

如果你有一些变量要绑定(bind)

$scope.data = [{
    {text: 'Certificado de cobertura sin nómina de personal', value: '1'},
    {text: 'Certificado de cobertura con nómina de personal completa', value: 'CNC'},
    {text: 'Certificado de cobertura con nómina de personal parcial', value: 'CNP'}
]

<span ng-repeat="item in data">
    <input type="radio" name="grupoRadio" ng-value="item.value" ng-model="valor" > {{item.text}}
</span>

关于javascript - Angularjs 单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43053656/

相关文章:

MYSQL 的 PHP 脚本作用于一个文件,而不作用于另一个文件

javascript - 编辑对传递参数的引用不会更新模型

javascript - 改变? : (ValueType, ActionMeta) => void,与 OptionType 不兼容

javascript - 带水平标签的 HTML 页面

javascript - node.js,测试 mongodb 保存和加载

javascript - 设置 box-sizing 以使用 content-box 后,Slickgrid 单元格边框被剪裁

javascript - 为什么我的 Async 和 Await 仍然没有完成序列执行的工作

JavaScript 与脚本文件放置位置混淆

javascript - 有没有办法在 Jasmine 测试中整合 'spyOn' 设置?

javascript - 调整div大小时如何保持用户的滚动位置