how to Create dynamic input form which is able to

2019-09-14 18:16发布

问题:

This is my mongoose schema

var VoSchema =new Schema({
  name:{type: String, 
  required: true},
  price:{type: String},
  feeds : [Schema.Types.Mixed]
 }, {strict: false});

Dynamic input field

 <div ng-repeat="item in inputs">
<div>
      <input ng-model="item.description">
    </div>
    <div>
      <input ng-model="item.qty">
    </div>
    <div>
      <input ng-model="item.cost"/>
    </div>
    <div >
      {{item.cost * item.qty}}
    </div>
  </div>
    <a class="btn btn-primary" href ng-click="addfield()" >[+]</a>
</div>

controller for angularjs

$scope.submitx = function(inv){
      $scope.inv.feeds = $scope.inputs.item
        console.log(inv);

            PostBlog.createInvoice(inv).then(function(data){
          console.log(data);
        });
            $scope.inv= {};
      }

   $scope.inputs = [];
   $scope.addfield=function(){
    $scope.inputs.push({ qty:0, cost:0, description:"" })
 }

I want to push the data in array to mongodb, how can i achieve this? please explain if possible in detail? how to use dynamic form in mean stack.