I can't get the values for radio button inputs in angular 2 forms to show up.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I was able to get the values using RadioButtonState.
https://angular.io/docs/ts/latest/api/common/index/RadioButtonState-class.html
Template
<div>
<h1>form test</h1>
{{isAdminYes.checked}}
<form [ngFormModel]="regForm">
<input type="radio" ngControl="isAdmin" name="isAdmin" [checked]="true" [(ngModel)]="isAdminYes" > Yes
<input type="radio" ngControl="isAdmin" name="isAdmin" [(ngModel)]="isAdminNo" > No
</form>
</div>
Component
export class App {
public isAdminYes : RadioButtonState = new RadioButtonState(true, "yes");
public isAdminNo : RadioButtonState = new RadioButtonState(false, "no");
constructor() {
this.regForm = new ControlGroup({
isAdmin: new Control(true)
});
}
}
Working plunker http://plnkr.co/edit/NnT8uRAr3xjxKB1hYfxT?p=preview