【问题标题】:Angular JS and raido buttonsAngularjs 和单选按钮
【发布时间】:2013-08-31 00:07:36
【问题描述】:

有谁知道默认情况下如何使用 Angular JS 检查单选按钮?我试过做

<input type= "radio" value= "point" checked= "checked"></input>
<input type= "radio" value= "range"></input>

这行得通,但是当我尝试在混合中添加一点 Angular JS 时

<input type= "radio" value= "point" ng-model= "mode" checked= "checked"></input>
<input type= "radio" value= "range" ng-model= "mode"></input>

这停止工作,即.. 当我加载页面时,默认情况下不再检查任何内容。有谁知道 angular 确保默认检查某些内容的方式?我需要检查一些东西,因为我在加载页面时显示的 html 最终将与选择的两个单选按钮中的任何一个相关联。

谢谢

【问题讨论】:

  • 使用不同的模型并在控制器中设置为true。
  • like $scope.point_mode = true 像这样?
  • @Zack - 将模型设置为您要检查的值,例如 point
  • @Zack 是的,不过最好使用 tymeJVs 解决方案。

标签: angularjs radio-button


【解决方案1】:

ng-model 设置为等于您要检查的收音机的value

<input type= "radio" value= "point" ng-model= "mode"></input>
<input type= "radio" value= "range" ng-model= "mode"></input>

$scope.mode = "point";

【讨论】:

  • 后续问题,有没有办法使用 Angular JS 隐藏 div 元素,直到选择范围单选按钮
猜你喜欢
  • 1970-01-01
  • 2012-09-17
  • 2013-09-02
  • 2015-02-17
  • 2017-06-21
  • 2018-05-10
  • 1970-01-01
  • 1970-01-01
  • 2016-03-01
相关资源
最近更新 更多