* ngForを使用したい次のコードがあります。コードには2つのラジオボタンしか表示されていませんが、もっと多くのラジオボタンがあります。ラジオボタン生成のための@ngForテンプレートの使用
options: string[] = [
'Single',
'Married',
'Divorced',
'Common-law',
'Visiting'
];
<input
#single
class = 'with-gap'
name = 'group3'
type = 'radio'
id = 'single'
value = 'Single'
(change) = 'radioBtnChange$.next(single.value)'/>
<label for = 'single'>Single</label>
<input #married
class = 'with-gap'
name = 'group3'
type = 'radio'
id = 'married'
value = 'Maried'
(change) = 'radioBtnChange$.next(married.value)'/>
<label for = 'married'>Married</label>
個々のラジオボタンを作成する代わりに、どのように@ngForを使用すればコードを簡潔にすることができますか。次のように
EDIT1 libararyの構文は次のとおりです。
<input class="with-gap" name="group3" type="radio" id="test5" checked />
<label for="test5">Red</label>
それは私がラベルで入力をラップ試してみましたが、ラベルのみが表示されますhttp://materializecss.com/forms.html
の一部です。任意の入力のための
感謝。
EDIT2
<label *ngFor="let option of options" for='option' >
<input
#option
type="radio"
class = 'with-gap'
name='group3'
id='option'
[value]='option'
(change) = 'radioBtnChange$.next(option.value)'/>
</label>
これまでと同じように、何も表示されませんでした。 –
何が起こったのでしょうか? –
私は最初にそれを包んだとき自分自身と思った - 私はタイプ= 'ラジオ'を持っていた。しかし、それはしませんでした。エラーはありません。何も表示されませんでした。私はdivとラベルでeverthingを置く。ラベルは表示されますが、* ngForテンプレートからは何も表示されません。 を使用しているライブラリの構文を覚えておいてください。 l'at [http://materializecss.com/forms.html](http://materializecss.com/forms.html)#radio –