【问题标题】:dynamic data from the server radio need to be checked需要检查来自服务器无线电的动态数据
【发布时间】:2017-04-16 05:35:58
【问题描述】:

我正在构建一个应用程序,我将在其中包含诸如性别之类的单选按钮。

所有数据都来自服务器,甚至还需要检查哪个单选按钮。

我将这些数据保存在 ng-checked 中,但它没有更新 ng-model。

通过使用该模型,我正在处理要显示的其他一些 div,因为 ng-model 没有更新,我无法显示该数据。

谁能帮我解决这个问题?或任何关于自定义指令可以通过从 ng-change 或 ng-checked 获取数据来更新 ng-model 的建议

even I am setting ng-model dynamically, like this everything in ng-repeat 

<input type="{{controls.type}}" class="form-control input-lg mandatory mapping_input radio" id="{{$parent.$parent.$index}}_{{controls.id}}" a ng-model="formData[$parent.$parent.$index][controls.name]" value="{{controls.id}}" name="control_{{$parent.$parent.$index}}_{{controls.name}}" ng-class="{checkbox_item : element.type == 'checkbox'}" autocomplete="off" ng-checked="setthecheckboxvalue(formData[$parent.$parent.$index][controls.name],controls.value)" ng-required="controls.mandatory">

【问题讨论】:

标签: angularjs


【解决方案1】:

您不需要 ng-checked 来实现此目的。只需使用input elementng-modelvalue 属性

<input type="radio" name="male" value="male" ng-model="data.gender"> Male
<input type="radio" name="female" value="female" ng-model="data.gender"> Female

将检查从服务器接收的数据是male 还是female

希望这会有所帮助!

【讨论】:

  • 我拥有一切动态的东西,即使是 ng-model,这个代码也能与这个 cae 一起工作。我已经用代码编辑了我的问题。你能检查一下吗
  • @raghuveerambedkar 请注意,根据 Angular 的文档 - ng-checked 不应与 ng-model 放在一起,这可能会导致意外行为。 docs.angularjs.org/api/ng/directive/ngChecked
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-17
  • 1970-01-01
  • 1970-01-01
  • 2015-05-13
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
相关资源
最近更新 更多