1

对于我尝试引用输入到我的表单中的值的每个实例,我都会收到这个有趣的Property 'notes' does not exist on type '{ [key: string]: AbstractControl; }'.错误。造成这种情况的线是'notes': this.addForm.controls.notes.value。我究竟做错了什么?

这是错误的整个上下文

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

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

这是从中检索值和调用方法的形式。

<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>
4

1 回答 1

2

FormControl 可以通过以下方式访问:

'notes': this.addApiForm.controls['notes'].value
于 2017-01-13T05:05:49.333 回答