【发布时间】:2018-07-18 05:02:02
【问题描述】:
我有一个 Angular 表单,它从用户那里获取输入并将其转换为 JSON 对象。
我需要这样的输出:
{"Name":"sam","age":"21","Friends":[{"Name":"bob","mobile":["123","456","789"]}]}
我需要另一个 JSON 列表中没有键的 JSON 值
"mobile":["123","456","789"]
我正在使用响应式表单并创建了一个嵌套的 FormArray,通过这样做,我可以获得如下输出:
{"Name":"sam","age":"21","Friends":[{"Name":"bob","mobile":"123"}]}
但是,如何仅使用上面提到的值(无键)创建另一个嵌套的 FormArray?
我的组件.ts
this.peopleList = this._fb.group({
Name : '',
age : '',
Friends: this._fb.array([this.CreateFriendList()])
});
CreateFriendList(): FormGroup {
return this._fb.group({
Name: '',
mobile : '',
});
}
【问题讨论】:
-
为什么需要手机":["123","456","789"] ?
-
拥有手机号码列表
-
它只是一种格式吗?为什么你的手机号只有9位?
-
3位数字只是一个例子,一个占位符而不是让它变大
-
你可以有一个 FormGroups 的 FormArray 或一个 FormControls 的 FormArray。 .html 中有几个不同之处。你可以在我的回答中看到一个例子stackoverflow.com/questions/51136985/…
标签: json angular angular5 angular6