模型不会在Angular 2无线电列表中更新 [英] Model won't update in Angular 2 radio list
问题描述
我正在尝试构建一个Angular 2组件,该组件显示带有无线电的选项列表。它工作正常,但它是组件的答案
字段,它绑定在 [(ng-model)] =answer$ c选择其中一个选项时,$ c>将不会更新。我做错了什么或者这不是创建无线电选择选项列表的方法吗?
I'm trying to build a Angular 2 component which displays a list of options with radios. It works fine but it the answer
field of the component, which is bound inside [(ng-model)]="answer"
, won't update when selecting one of the options. Am I doing something wrong or isn't this the way to create a list of radio selection options?
<div>
Answer: {{ answer }}
</div>
<div class="radio" *ng-for="#option of itemData">
<label>
<input type="radio" [value]="option.id" [(ng-model)]="answer"
(change)="responseChanged()" name="radio-list">
<span>{{ option.name }}</span>
</label>
</div>
推荐答案
我猜双向绑定现在正在使用无线电,所以目前你不能使用 [(ng-model)]
。
Well i guess two way binding is now working with radio, so currently you cannot use [(ng-model)]
.
另一种方法是使用change事件和checked属性。查看我的plunker
The alternative is to use the change event and checked attribute. See my plunker
http://plnkr.co/edit/ 7Zm3qgoSv22Y9KrBn4tS?p =预览
(更改)=answer = $ event.target.value
和
[checked] ='answer == option.id'
这篇关于模型不会在Angular 2无线电列表中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!