【发布时间】:2019-04-01 04:14:06
【问题描述】:
我有一个不属于表单的单选按钮列表。我想根据一个值将其中一个设置为 true。
然后,当点击另一个时,所有其他都设置为 false,除了点击的那个。
单选按钮列表是动态的,由ngFor 生成,
我有类似的东西
<div *ngFor='let item of array;let i = index'>
<input type="radio" [checked]=false (click)='radioChecked(item.id,i)' > <input type="text" value='{{item.name}}' > <button type="button" >save</button>
</div>
ngOnInit() {
this.myService.getNumber(id).subscribe((data) =>{
//when the page loads, set one of radiobuttons to true
//somehow get the id and set to true, no standard is, since dynamic list
radioId.value = true;
})
}
radioChecked(id, i){
//turn all the others to false, except this one
}
由于这不是表格,也没有标准行,所以我可以有一个 id,我该怎么做?我使用角度 6
谢谢
【问题讨论】:
标签: angular radio-button angular6