【发布时间】:2018-11-03 06:35:03
【问题描述】:
我是新的 angular ,在我的 angular 4 项目中,我有一个 JSON 数组,我通过它制作一个复选框列表。我无法提交这些动态复选框的值。
我的 json 数组是:-
let chekboxArray =
[
{
section:'Programming Skills',
choices:[
{
name:'C'
value:'c'
},
{
name:'C++'
value:'c++'
},
{
name:'Java'
value:'java'
}
]
},
{
section:'Interest',
choices:[
{
name:'Movies'
value:'movies'
},
{
name:'Tv Series'
value:'tvseries'
},
{
name:'Football'
value:'football'
}
]
}
]
我的 HTML 是:-
<form #customChoiceform="ngForm" (ngSubmit)="addToCart(customChoiceform);">
<div *ngFor="let single of chekboxArray">
<label>{{ single.section }}</label>
<div *ngFor="let choice of single.choices;let i=index">
<label>{{ choice.name }}</label>
<input type="checkbox" [value]="{{ choice.value }}" name="{{ 'choices'+i }}" />
</div>
</div>
<div>
<button type="submit" />Submit</button>
</div>
</form>
在我的 component.ts 文件中:
addToCart(form:NgForm){
console.log(form);
}
请帮助如何管理这种事情。这将对我的项目有所帮助。
【问题讨论】:
-
你没有表单结束标签?
标签: angular angular5 angular-forms