luc*_*ssp 3 javascript web-component angular
我正在尝试构建一个Angular 2组件,它显示带有无线电的选项列表.它工作正常,但是当选择其中一个选项时,answer组件的字段(内部绑定[(ng-model)]="answer")将不会更新.我做错了什么,或者这不是创建无线电选择列表的方法吗?
<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>
Run Code Online (Sandbox Code Playgroud)
嗯,我想两种方式绑定现在使用无线电,所以目前你不能使用[(ng-model)].
另一种方法是使用change事件和checked属性.看我的傻瓜
http://plnkr.co/edit/7Zm3qgoSv22Y9KrBn4tS?p=preview
(change)="answer=$event.target.value"
和
[checked]='answer==option.id'
| 归档时间: |
|
| 查看次数: |
3432 次 |
| 最近记录: |