Javascript AngularJS,添加两个额外的输入文本框,id和ng模型,它们不会被提交

Javascript AngularJS,添加两个额外的输入文本框,id和ng模型,它们不会被提交,javascript,angularjs,json,angularjs-ng-form,angularjs-model,Javascript,Angularjs,Json,Angularjs Ng Form,Angularjs Model,我一直在修改一个表单,我已经做了很多次了。这一次我不明白为什么它不发送两个额外的字段 控制器 vm.question = {}; vm.question.VerbiageSpanish = ""; vm.question.ParentId = ""; vm.question.ParentValue = ""; 现在大多数情况下它们都是空白的,但我不记得空白字段值没有被发送的问题 有效的现有字段 <div class="form-group"> <label class

我一直在修改一个表单,我已经做了很多次了。这一次我不明白为什么它不发送两个额外的字段

控制器

vm.question = {};
vm.question.VerbiageSpanish = "";
vm.question.ParentId = "";
vm.question.ParentValue = "";
现在大多数情况下它们都是空白的,但我不记得空白字段值没有被发送的问题

有效的现有字段

<div class="form-group">
   <label class="col-md-2" for="english">Spanish</label>
   <div class="col-md-10">
     <input type="text" ng-model="vm.question.VerbiageSpanish"
             id="verbiagespanish" name="verbiagespanish"
             class="form-control"
             placeholder="Spanish" />
   </div>
</div>
作为代码的示例,请注意,它包含VerbiageSpanish和除新的ParentId和ParentValue之外的所有其他字段 这怎么可能

{
  "Active": true,
  "Name": "test",
  "Description": "test",
  "Verbiage": "test",
  "VerbiageSpanish": "test",
  "directive": {
    "1": true
  },
  "data": {
    "1": "yes"
  },
  "SortOrder": {
    "1": "2"
  }
}
根据评论更新:

  • 如果我填写ParentId和ParentValue,那么我会看到它被发送过来,就像我看到console.log一样

  • 表单提交按钮

     <button type="button" class="btn btn-success" data-dismiss="modal"
             ng-click="vm.saveQuestion(vm.question)">
        Save
     </button>
    
  • 当我将数据放入这些文本框时,我看到了这一点

    {
      "Active": true,
      "Name": "test",
          "ParentId" : "22",
          "ParentValue": "afafaf",
      "Description": "test",
      "Verbiage": "test",
      "VerbiageSpanish": "test",
      "directive": {
        "1": true
      },
      "data": {
        "1": "yes"
      },
      "SortOrder": {
        "1": "2"
      }
    }
    

    我认为要么像在控制器中一样初始化这些键

    vm.question = {};
    
    vm.question.VerbiageSpanish = "";
    vm.question.ParentId = "";
    vm.question.ParentValue = "";
    
    或 在这些字段中使用
    ng init=”“

    <input type="text" ng-model="vm.question.ParentValue"
           style="width:220px" id="parentvalue" name="parentvalue" 
           class="form-control"
           ng-init="" placeholder="Parent Value" />
    
    
    
    确实要将这两个字段放在同一个表单中吗?显示用于发布此内容的API调用。我想你没有附加上述内容fields@WasifKhan-在“提交”按钮上,它只向我发送所填写内容的值:/这不正常,对吗?也许我做表单的方式不好?@Vivz-你是什么意思,我用更多的代码编辑了问题,thx in advanceI我假设你使用的是ControllerAs语法?(即,'vm')如果是的话,在控制器中你会有这个问题;另外-不要将vm.question从模板传递给controller方法,不要传递任何东西,但是在方法中,对这个.question进行操作-console.log会给你什么?好吧,我想知道我写的每个angularjs表单,我是否应该根据angularjs/ng模型似乎“工作”的方式初始化所有表单我也签入了我的项目,是的,在JSON中,它在获得值之前不会生成键值。@JohnBaxter您可以使用
    required
    属性通知用户未填充的字段,并在输入数据之前禁止表单提交功能。这提供了比单独的服务器端验证更好的用户体验,因为用户可以获得关于如何纠正错误的即时反馈。有关更多信息,请参阅。另请参阅。值的初始化不起作用,我很惊讶它们不在那里-我将尝试ng init。。。。在发送到api之前,我必须添加不起作用的内容,或者在node.js中,我必须检查req.body中的值:/