【问题标题】:How do I make a form group to insert an array into my db?如何创建表单组以将数组插入到我的数据库中?
【发布时间】:2021-11-05 21:27:19
【问题描述】:

这是我当前的表单组


ngOnInit(){
    this.admQuizForm = this.fb.group({
      name:'',
      desc:'',
      type:'',
      date: new Date(),
      questions: [
       .....what do i do here
      ]
    });
  }

这是我的数据库条目

{"_id":{"$oid":"611b2ba2f29......."},
"name":"quiz1",
"desc":"quiz1",
"type":"history",
"date":"",
"questions":[
{"options":["1","2","3","4"],"question":"whats?","answer":"4"},
{"options":["2","3","4","1"],"question":"whats?","answer":"4"},
{"options":["123","asd","fsa","test"],"question":"whats?","answer":"test"},
{"options":["asd","ads","dsa","aadd"],"question":"whats?","answer":"aadd"}
]}

我正在尝试创建一个表单组以通过我的网站添加新的测验,该网站使用 angular 和 typescript,但我不确定数组如何在表单组中工作。我手动将数据添加到数据库中。

【问题讨论】:

标签: html node.js angular typescript


【解决方案1】:

您需要使用 FormArray When to use FormGroup vs. FormArray? 表单组将使用保存为对象,表单数组将其保存为数组

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2013-11-30
    • 2021-01-12
    • 2017-07-10
    相关资源
    最近更新 更多