Angular 8:表单控件,表单控件没有值访问器,名称为:"StartDateForm"



我的代码如下所示:

export class SearchByParametersComponent implements OnInit {
parametersForm=new FormGroup({
NumAppForm:new FormControl (''),
UniqeIDForm :new FormControl (''),
StartDateForm :new FormControl (''),
EndDateForm :new FormControl (''),
NumStatusForm :new FormControl (''),
});

showAll()
{
//x:string
debugger;
this.NumApp=this.parametersForm.controls.NumAppForm.value;
this.x=this.parametersForm.controls.UniqeIDForm.value;
this.NumStatus=this.parametersForm.controls.NumStatusForm.value;
this.sd=this.parametersForm.controls.StartDateForm.value;
// this.sd= this.parametersForm.get('StartDateForm').value;
// this.ed=this.parametersForm.controls.EndDateForm.value;
console.log(this.parametersForm);
if (this.NumApp==undefined) {
alert("חובה לבחור מספר מערכת");
}
else
{
if (this.x!="" && this.x!=undefined)
{
this.ParametersToSearch.NumApp=this.NumApp;
debugger;
this.ParametersToSearch.UniqeID=String(this.x);
debugger
this.checkUniqeId.emit(this.ParametersToSearch);
debugger;
this.ParametersToSearch=new ParametersToSearchDTO();
debugger;
//this.checkUniqeId.emit(x);  
}
else  if (this.StartDate != null  && this.EndDate != null)
{
this.DateObject.StartDate=String(this.StartDate["day"]+"-"+this.StartDate["month"]+"-"+this.StartDate["year"]);
this.DateObject.EndDate=String(this.EndDate["day"]+"-"+this.EndDate["month"]+"-"+this.EndDate["year"]);
this.DateObject.NumApp=this.NumApp;
debugger;
this.checkRangeDate.emit(this.DateObject);
this.DateObject=new DateRangeDTO();
debugger;    
}
else  if(this.NumStatus!="" && this.NumStatus!=undefined)
{
debugger;
this.StatusSearch.NumApp=this.NumApp;
this.StatusSearch.NumStatus=this.NumStatus;
this.checkStatus.emit(this.StatusSearch);
this.StatusSearch=new StatusSearchDTO();
debugger;
}
else 
{
debugger;
this.checkNumApp.emit(this.NumApp);
debugger;
}
}


<form [formGroup]="parametersForm">
<div class="myPage">
<div class="form-group title1">
<span> קוד מערכת <span class="must" title="שדה חובה">*</span></span>
</div>
<div class="form-group title2">
<select class="form-control" formControlName="NumAppForm"
(change)="onChangeApp($event.target.value)" required>
<option>----------</option>
<option *ngFor="let index of ListApp">{{index}}</option>
</select>
</div>
<div class="form-group title3">
<span dir="rtl"> UniqeId </span>
</div>
<div class="form-group title4">
<input class="form-control"  formControlName="UniqeIDForm" type="text">
</div>
<div class="form-group title5">
<span class="line"> צרוף קובץ מ</span>
</div>
<div class="form-group title6">
<app-date-picker formControlName="StartDateForm" (dateSelect)="dateSelectStart($event)"></app-date-picker>
</div>
<div class="form-group title7">
<span class="line"> עד</span>
</div>
<div class="form-group title8">
<app-date-picker  formControlName="EndDateForm" (dateSelect)="dateSelectEnd($event)" ></app-date-picker>
</div>
<div class="form-group title9">
<span> סטטוס</span>
</div>
<div class="form-group title10">
<select class="form-control" formControlName="NumStatusForm" (change)="onChangeStatus($event.target.value)">
<option>----------</option>
<option *ngFor="let index of ListStatus">{{index}}</option>
</select>
</div>
</div>
</form>
<button type="submit" dir="ltr"  class="btn btn-primary" (click)="showAll(); reset()">אישור</button>

<!-- <input class="radio" type="checkbox" title="הכנס UniqeId" label="הכנס" />  <br> -->
<!-- [(ngModel)]="NewUniqeId.value" -->
<!-- formControlName="StartDateForm" -->
<!-- formControlName="EndDateForm" -->
<!-- [formControl]="parametersForm.controls.StartDateForm" -->

Angular 8上的一个项目:我有一个HTML格式的DATE-PICKER标记我有一个包含更多标签的FORM-CONTROL,比如:输入,选择。。。所有FORM-CONTROL元素都已识别通过FROM-CONTROL-NAME属性但是只有DATE-PICKER元素是未知的,并且在尝试将FROM-CONTROL-NAME属性设置为它时出错我们能做什么?我需要在FORM中了解它,这样我就可以一键清除所有带有元素的内容。。。。。

app-date-picker不是表单控件,因此无法设置formControlName。该组件应该实现ControlValueAccessor以作为表单控件工作。如果您需要构建自定义表单控件,请参阅

Angular 2-formControlName内部组件

最新更新