gpt4 book ai didi

javascript - Angular2 - RadioButtonState 没有按预期工作

转载 作者:行者123 更新时间:2023-11-30 16:05:14 25 4
gpt4 key购买 nike

我在尝试使 RadioButtonState 按预期工作时遇到了一些麻烦。我尝试通过以下方式使用 RadioButtonState:

import {Component} from '@angular/core';
import {RadioButtonState} from '@angular/common';
import {bootstrap} from '@angular/platform-browser-dynamic';

@Component({
selector: 'my-app',
template:`
Select Gender:
<span *ngFor="let gender of inputs; let i=index" >
<input type="radio" name="gender" [(ngModel)]="inputs[i]" /> {{gender.value}}
</span>

<br>
{{inputs | json}}
`
})
export class AppCmp{
public inputs = [
new RadioButtonState(false,"Male"),
new RadioButtonState(false,"Female")
]
}

bootstrap(AppCmp);

当我单击任何单选按钮时,它会使值变为真,但在单选按钮之间切换不会再次使它们中的任何一个变为假。我重现了问题here on plunker .

最佳答案

这是一个已知问题 https://github.com/angular/angular/issues/7374

在解决此问题之前提到的解决方法:

<label class="radio-inline">
<input type="radio"
value="male"
#male
[checked]="child.gender === 'male'"
(click)="child.gender = male.value"
name="gender">Male</label>

<label class="radio-inline">
<input type="radio"
#female
value="female"
[checked]="child.gender === 'female'"
(click)="child.gender = female.value"
name="gender">Female</label>

关于javascript - Angular2 - RadioButtonState 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37142010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com