按方位角

时间:2017-08-18 20:11:52

标签: html forms angular formgroups

我目前正在使用单选按钮和表单获得一些奇怪的功能。

基本上我有一个带有4个单选按钮的表单。现在:当我点击一个单选按钮时,它会永久启用。因此,我可以选择所有4个选项。单击该选项不会取消选择无线电选项。

我希望它在选项之间切换,所以我一次只能选择1个选项。我错过了什么?

我的代码:

<form [formGroup]="answer" (submit)="saveAnswer()">
    <input formControlName="answer" id="option1" type="radio" />
    <input formControlName="answer2" id="option2" type="radio" />
    <input formControlName="answer3" id="option3" type="radio" />
    <input formControlName="answer4" id="option4" type="radio" />
    <button type="submit">Submit</button>
</form>

constructor(
 private movieService: MovieService,
 private formBuilder: FormBuilder
) {
 this.answer = this.formBuilder.group({
   'answer': '',
   'answer2': '',
   'answer3': '',
   'answer4': ''
 });
}

1 个答案:

答案 0 :(得分:1)

如果您希望单选按钮分组&#34;在一起(所以你只能选择其中一个)你应该给它们所有的名字相同:

DbFunctions.DiffDays(DateTimeOffset.Now, x.EventDate) == 0

您可以使用<form [formGroup]="answer" (submit)="saveAnswer()"> <input formControlName="answer" value="answer1" id="option1" type="radio" /> <input formControlName="answer" value="answer2" id="option2" type="radio" /> <input formControlName="answer" value="answer3" id="option3" type="radio" /> <input formControlName="answer" value="answer4" id="option4" type="radio" /> <button type="submit">Submit</button> </form>

区分它们