我曾尝试这许多不同的方式:发现其中选择单选按钮,而无需使用* ngFor
<input type="radio" name="group" id="ssnRadio" [checked]="ssn" [(ngModel)]="ssnSelected">
和
<input type="radio" name="group" [checked]="lastName" [(ngModel)]="lastNameSelected" >
有多个无线电按钮,但它们是加紧像上面。他们都在A组份*ngFor
因此分离不是我有以下几点:
ssnSelected: boolean;
userIdSelected: boolean;
lastNameSelected: boolean;
officeSelected: boolean;
roleSelected: boolean;
selectedRow: number;
ngOnInit(){
this.ssnSelected=false;
this.userIdSelected=false;
this.lastNameSelected=false;
this.officeSelected=false;
this.roleSelected=false;
}
并且按钮有这种方法在它时,它:
search() {
if (this.ssnSelected==true) {
console.log(this.ssn);
this.user = this._searchService.getUserBySSN(this.ssn);
}
if (this.userIdSelected == true) {
console.log(this.userId);
this.user = this._searchService.getUserById(this.userId);
}
所以我需要找到什么单选按钮被选中,所以我可以调用正确的服务,并传入一个使用双向绑定到服务的值。
我有,但我需要它具有单选按钮功能。他们只能选择一个复选框,当他们选择另一个复选框时,先前的复选框将被取消选中。因此单选按钮功能。 – Drew1208
@ Drew1208:根据您的评论更新回答,干杯! –
你钉了它! – Drew1208