2017-05-03 92 views
-1

我有一个多表单,我只想提交时除了这个值。我只想只读取圈出的数据。如何在Angular 2的指定FormBuilder上除名/删除名称

enter image description here

这是我当前的代码。

addIngredient (itemId: string, name: string, quantity: number, unit: string): void { 
    const ingControl = <FormArray>this.item.controls['ingredients']; 

    ingControl.push(this.fb.group({ 
     itemId: [itemId || '', Validators.required], 
     name: [name || '', Validators.required], 
     quantity: [quantity || 0, Validators.required], 
     unit: [unit || 'Grams', Validators.required] <----------- 
    })); 
    } 

这是对onsubmit enter image description here

+0

能否请您贴上您提交方法 – sainu

+0

我对你想要排除的东西有点困惑。第一张照片,你说你只想从圈子中得到数值,这是克数,然后在其他图片中,你说你想用克数去除数值? – Alex

回答

0

不知道,如果你的要求是:

submit(formvalue: any){ 
    //you may creat an object 
    let object: any = { 
    'itemId': formValue.itemId, 
    'name': formValue.name, 
    'quantity': formValue.quantity, 
    'unit': "", 
    }; 
// or whatever you lik 
formvalue.unit = ""; 

//YOUR API CALL 
} 

,并在你的HTML:

<form class="register-form" [formGroup]="yourForm" (ngSubmit)="submit(yourForm.value)"></form>