【发布时间】:2017-02-23 17:39:21
【问题描述】:
我尝试了很多不同的方法:
<input type="radio" name="group" id="ssnRadio" [checked]="ssn" [(ngModel)]="ssnSelected">
和
<input type="radio" name="group" [checked]="lastName" [(ngModel)]="lastNameSelected" >
还有更多单选按钮,但它们像上面一样逐步增加。它们都是分开的,因此不在*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);
}
所以我需要找到选择了哪个单选按钮,这样我才能调用正确的服务并传入一个使用两种方式绑定到服务的值。
【问题讨论】:
标签: angular