Я создаю форму для редактирования клиентов, но по некоторым причинам я получаю много ошибок.Первой ошибкой является «Ошибка: formGroup ожидает экземпляр FormGroup. Пожалуйста, передайте один вход.»мой HTML.
Я использую почти такую же конфигурацию в другом компоненте, и он работает нормально, я не могу понять, почему это вызывает у меня ошибки.
this.myGroup = new FormGroup({
firstName: new FormControl()
});
<form [formGroup]="modifyClientForm" [ngClass]="{'view-only': inViewMode}" (ngSubmit)="modifyClient()">
<!--BLOCK 1: TAB 1 start-->
<div *ngIf="activeTab==='clientName'" class="white-bg">
<div class="form-row">
<div class="form-group col-12">
<label for="companyName">Ettevõtte nimi<span *ngIf="!inViewMode" class="required">*</span></label>
<input class="form-control" formControlName="companyName" name="companyName" id="companyName">
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-12 col-md-6">
<label for="firmRegNo">Reg number<span *ngIf="!inViewMode" class="required">*</span></label>
<input formControlName="firmRegNo" class="form-control" name="firmRegNo" id="firmRegNo">
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-12">
<label for="address">Aadress</label>
<input class="form-control" id="address" name="address" formControlName="address" >
</div>
</div>
<h4 class="form-title-mt">Kontakt</h4>
<div class="form-row">
<div class="form-group col-sm-12">
<label for="clientName">Kliendi nimi</label>
<input class="form-control" id="clientName" name="clientName" formControlName="clientName">
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">
<label for="phoneOne">Telefon 1</label>
<input class="form-control" id="phoneOne" name="phoneOne" formControlName="phoneOne">
</div>
<div class="form-group col-sm-6">
<label for="phoneTwo">Telefon 2</label>
<input class="form-control" id="phoneTwo" name="phoneTwo" formControlName="phoneTwo" >
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-12">
<label for="email">Email</label>
<input class="form-control" id="email" name="email" formControlName="email">
</div>
</div>
<div class="form-row mt-3">
<div class="form-group col-sm-12">
<label for="explanation">Selgitus</label>
<textarea class="form-control" id="explanation" name="explanation" placeholder="Hetkel puudub" formControlName="explanation"></textarea>
</div>
</div>
</div>
<!--BLOCK 1: TAB 1 end-->
<!--BLOCK 1: TAB 2 start-->
<div *ngIf="activeTab==='contract'" class="white-bg">
<app-client-contracts [activeClient]="activeClient"></app-client-contracts>
</div>
<!--BLOCK 1: TAB 2 end-->
<!--BLOCK 1: TAB 3 start-->
<div *ngIf="activeTab==='files'" class="white-bg">
<!-- Todo: kliendi failid -->
</div>
<!--BLOCK 1: TAB 3 end-->
машинопись:
modifyClientForm: FormGroup;
activeClient: Client;
constructor(private clientService: ClientService, private formBuilder: FormBuilder) { }
ngOnInit() {
this.inViewMode = true;
this.clientId = parseInt(window.location.pathname.split('/')[2], 10);
this.clientService.getClientById(this.clientId)
.subscribe(data => this.activeClient = data);
this.modifyClientForm = this.formBuilder.group({
companyName: [this.activeClient.companyName],
firmRegNo: [this.activeClient.firmRegNo],
address: [this.activeClient.address],
clientName: [this.activeClient.clientName],
phoneOne: [this.activeClient.phoneOne],
phoneTwo: [this.activeClient.phoneTwo],
email: [this.activeClient.email],
explanation: [this.activeClient.explanation]
});
}