[英]Need help building Reactive Form of Radio Input List
I want to realize my selection with reactive Forms, i am new to this so here is my code: 我想用反应式表单实现选择,对此我是新手,所以这是我的代码:
I already tried to implement it with the documentation and the provided examples, but with no luck and destoying my single select radio button selection input. 我已经尝试使用文档和所提供的示例来实现它,但是没有运气,也无法理解我的单选单选按钮选择输入。 What do i need to implement in my .ts file and here in my html snippet to realize that? 我需要在.ts文件和html代码段中实现什么才能实现这一点?
Here is my working HTML Snippet: 这是我的HTML代码段:
<div *ngFor="let stream of myList">
<label>
{{ stream.sys }}
</label>
<p *ngFor="let type of stream.types">
<tr>
<input type="radio" name="nav"/>
{{ type.type.label }}
</tr>
</p>
</div>
I am looping over the outer list and the inner list with input Type radio. 我用输入类型收音机遍历外部列表和内部列表。 Everything works fine. 一切正常。 Now i want to implement it to be Reactive Forms: 现在我想将其实现为反应形式:
This is my desired Output for example: 这是我想要的输出,例如:
Test
o Number 1
Test2
o Number 10
o Number 20
Test3
X Number 100
Value: Number 100 // or some id i have in my input data -> type.type.id
This navigation needs to be a select of one item and i want to show the form value unter my list as first step. 此导航需要选择一项,我想在第一步中显示列表后的表单值。
I tried something like this: 我尝试过这样的事情:
.html html的
<form [formGroup]="form">
<div *ngFor="let stream of myList">
<label>
{{ stream.sys }}
</label>
<p *ngFor="let type of stream.types">
<tr>
<input type="radio" name="name" formControlName="name" />
{{ type.type.label }}
</tr>
</p>
</div>
</form>
<p>
Value: {{ form.value | json}}
</p>
.ts .TS
form: FormGroup;
constructor(private formBuilder: FormBuilder) {
this.form = formBuilder.group({
name: ['']
});
<tr>
is incorrect in a <p>
. 这与问题无关,但我认为<tr>
在<p>
不正确。 Instead you could just add the loop on a div instead of a paragraph and then remove the tablerow 相反,您可以只在div而不是段落上添加循环,然后删除tablerow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.