gradingKey.currentAnswerは、最初に値がフォームに追加されたときにラジオボタンにバインドされません。複雑なオブジェクト上のラジオボタンバインディングを使用する角4の反応形式は機能しません
なぜ機能しないのですか? How to set the selected radio button initially in *ngFor on radiobutton group
HTML
<form [formGroup]="gradingKeyForm">
<div class="form-group row">
<label class="col-6 col-form-label">{{getHalfScoresErrorsCount()}}</label>
<div class="col-6">
<span *ngFor="let answer of gradingKey.halfScoresCountAnswers">
<label class="radio-inline">
<input type="radio" (ngModelChange)="onChangeHalfScoresErrorsCount($event)"
formControlName="halfScoresCount" [value]="answer">
{{answer.value}}
</label>
</span>
</div>
</div>
</form>
コンポーネント
ngOnInit() {
this.gradingKeyForm = this.fb.group({
halfScoresCount: this.gradingKey.currentAnswer,
});
}
モデル
:これは、角度4を参照してくださいする前に一度働いていました
import KeyValue from '../keyvalue';
import { IGradingKey } from './shared/grading-key-interface';
export default class GradingKey implements IGradingKey {
halfScoresCountAnswers: KeyValue<boolean, string>[];
currentAnswer: KeyValue<boolean, string>;
constructor(obj: any) {
this.halfScoresCountAnswers = [new KeyValue(true, 'Ja'), new KeyValue(false, 'Nein')];
this.currentAnswer = obj.halfScoresCount == true ? this.halfScoresCountAnswers[0] : this.halfScoresCountAnswers[1];
}
}
私は 'にチェックを使用することはありませんので、あなたが、plunkerを作成することができます'ここでは、やってみようとするプランクを持っていると助けになるだろう。現在、問題を再現するのに十分なコードがありません。 – Alex
だから...あなたはすでに上記のコードで "バグ"を再現しようとしましたか?実際には必要なものはすべてそこにあります。後でplunkrを作成することができます... – Pascal