【发布时间】:2020-03-02 14:25:10
【问题描述】:
我在多选下拉列表中显示了一些列表。 提交的数据在表单中
[ "object1" , "object2" ]
我希望它以如下形式提交:
[ { object 1 } , { object 2} ]
我的 html 下拉列表代码:
<select name="service" multiple matNativeControl required ngModel>
<option *ngFor="let service of subCategoriesList" value="{{service.id}}">{{service.service}}</option>
</select>
Component.ts 文件:
addPackage(form: NgForm){
const body = {
package_name : form.value.name,
services: form.value.service, //the value required in objects in an array
}
console.log("add package body is: ", body)
任何帮助将不胜感激。
【问题讨论】:
-
请详细询问您想要什么,您尝试过什么以及有什么问题。如果你想得到好的回应,就问一个好问题。检查 stackoverflow.com/help/how-to-ask
标签: arrays angular forms angular2-template