要解决Angular 8中FormGroup的值始终为空的问题,可以按照以下步骤进行操作:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'app-my-form',
templateUrl: './my-form.component.html',
styleUrls: ['./my-form.component.css']
})
export class MyFormComponent implements OnInit {
myForm: FormGroup;
ngOnInit() {
this.myForm = new FormGroup({
myControl: new FormControl()
});
}
}
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
// ...
FormsModule,
ReactiveFormsModule
],
// ...
})
export class AppModule { }
以上是解决Angular 8中FormGroup值始终为空的一般步骤,根据具体问题可能还需要进一步的调试和排查。