错误 TS2339:属性 'f' 在类型 'ReactiveComponent' 上不存在

error TS2339: Property 'f' does not exist on type 'ReactiveComponent'

我是 angular 的新手。我正在制作一个反应式 angular 表单,在提交值后将在数组中显示值。我试图将验证器添加到表单中,并且大多数都工作正常。只有当我输入密码时,它才显示错误

error TS2339: Property 'f' does not exist on type 'ReactiveComponent'

我做错了什么? 我在这里先向您的帮助表示感谢 HTML 组件:

<h1>Reactive Form</h1>
<div>
    <form [formGroup]="newForm" (ngSubmit)="onSubmit()">
        <p>
            <label for="username">Username</label>
            <input type="text" formControlName="username" required>
        </p>
        <div *ngIf="f.username.invalid && (f.username.dirty || f.username.touched)">
            <div *ngIf="f.username.errors?.required">
                Username is required
            </div>
        </div>
        <p>
            <label for="email">Email</label>
            <input type="email" formControlName="email" required>
        </p>
        <div *ngIf="f.email.invalid && (f.email.dirty || f.email.touched)">
            <div *ngIf="f.email.errors?.required">
                Email not entered
            </div>
            <div *ngIf="f.email.errors?.email">
                Please enter valid email
            </div>
        </div>
        <p>
            <label for="password">Password</label>
            <input type="password" formControlName="password" required>
        </p>
        <div *ngIf="f.password.invalid && (f.password.dirty || f.password.touched)">
            <div *ngIf="f.password.errors?.required">
                Password is required
            </div>
            <div *ngIf="f.password.errors?.minlength">
                Password must be 6 characters
            </div>
        </div>
        <button type="submit">Submit</button>
    </form>

    <!-- <button (click)="removeItem()">Remove item</button> -->
    <button (click)="removeAll()">Remove all item</button>
</div>
<!-- <button (click)="updateUsername()">Update User</button> -->
<h1>
    {{ newForm.value }}
</h1>

reactive.components.ts:

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-reactive',
  templateUrl: './reactive.component.html',
  styleUrls: ['./reactive.component.css']
})
export class ReactiveComponent implements OnInit {
  newid!: any;

  newForm = new FormGroup({
    username : new FormControl('',[Validators.required]),
    email : new FormControl('', [Validators.required]),
    password : new FormControl('',[Validators.required, Validators.minLength(6)])
  });

  //username = new FormControl('');
  constructor() { }

  ngOnInit() : void{
    // this.display();
  }
  

  // display(){
  //   this.newid = localStorage.getItem('formdata');
  // }
  // updateUsername(){
  //   this.username.setValue('newusername')
  // }

  onSubmit(){
    var dataObject= this.newForm.value ;
    var array = JSON.parse(localStorage.getItem("formdata") || '[]')
    array.push(dataObject);
    localStorage.setItem("formdata",JSON.stringify(array));
  }

  // removeItem() {
  //   localStorage.removeItem('formdata');
  // }

  removeAll() {
    localStorage.clear();
  }
}
  1. 拍摄一张基于性别的图像,命名为 male-avatar.jpgfemale-avatar.jpg 并将它们放入您的服务器静态目录中。
  2. 当用户根据性别类型注册时,将这些图像名称作为字符串分配给您在数据库中的 user.avatar
  3. 在前端 (reactjs),您可以像这样使用从服务器接收到的数据
  <img src={`/${data.user.avatar}`} />