小编Cha*_*uri的帖子

属性“fName”来自索引签名,因此必须使用 ['fName'] 访问它

这些是我的文件。我收到此错误有人可以帮助我。

Error: src/app/app.component.html:5:123 - error TS4111: Property 'fName' comes from an index signature, so it must be accessed with ['fName'].
        <input id="name" type="text" formControlName="fName" class="form-control" [ngClass]="{'is-invalid':submitted && f.fName.errors}"/>

Run Code Online (Sandbox Code Playgroud)

组件.html

    <form [formGroup]="surveyForm" (ngSubmit)="onSubmit()">
      <div>
        <label>Name:</label>
        <input id="name" type="text" formControlName="fName" class="form-control" [ngClass]="{'is-invalid':submitted && f.fName.errors}"/>
        <div *ngIf="submitted && f.fName.errors" class="form-control">first name is required</div>
      </div>
    </form>
Run Code Online (Sandbox Code Playgroud)

组件.ts


    import { Component, OnInit } from '@angular/core';
    import { FormControl, FormBuilder, FormGroup, Validators} from '@angular/forms';
    @Component({
    selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
      })
      export class AppComponent implements …
Run Code Online (Sandbox Code Playgroud)

components angular-material angular

131
推荐指数
6
解决办法
17万
查看次数

标签 统计

angular ×1

angular-material ×1

components ×1