2017-01-13 11 views
1

Für jede Instanz, wo ich versuche, den Wert in mein Formular eingegeben beziehen, bekomme ich diese komische Property 'notes' does not exist on type '{ [key: string]: AbstractControl; }'. Fehler. Die Linie, auf die dies zurückzuführen ist, lautet 'notes': this.addForm.controls.notes.value. Was mache ich falsch?@ eckig/Formulare FormBuilder pops Eigenschaft existiert nicht auf Typ

Hier ist der gesamte Kontext des Fehlers

import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 

export class TheNewClass { 
    addApi(): void { 
     if (this.addApiForm.valid) { 
      Api.insert({ 
       'notes': this.addApi.controls.notes.value 
      }); 
     } 
    } 
} 

Hier ist die Form, in der die Werte aus, und das Verfahren abgerufen werden, wird genannt.

<form [formGroup]="addApiForm" (ngSubmit)="addApi()" class="inline-form"> 
    <div class="form-group"> 
     <label for="apiNotes">Notes</label> 
     <input id="apiNotes" formControlName="apiNotes" class="form-control" type="text" placeholder="Notes"> 
    </div> 
    <button type="submit" class="btn btn-primary">Add</button> 
</form> 
+0

können Sie etwas mehr Code teilen? – ranakrunal9

+0

@ ranakrunal9 sicher – gh0st

+0

Wie haben Sie 'addApi' formGroup definiert, auf das Sie innerhalb' TheNewClass' zugreifen? – ranakrunal9

Antwort

2

Formcontrol kann zugegriffen werden:

'notes': this.addApiForm.controls['notes'].value 
+0

das war es ... so einfach werde ich als Antwort markieren, wenn das Zeitlimit abgelaufen ist. – gh0st

Verwandte Themen