>
ngAfterViewInit() {
this.service.change.subscribe((data: Patient) => {
alert('in the detail component of ngAfterViewInit');
console.log(data);
this.ModelChange(data);
}) ;
}
,而ModelChange的代码如下
ModelChange(数据:患者){ this.form.controls ['PatientCode']。setValue(data.PatientCode);
}
我的html就像
<form #form="ngForm" autocomplete="on" (submit)="OnSubmit(form)">
<div class="row">
<div class="form-group">
<input name="PatientCode" [(ngModel)]="PatientCode"class="form-control" placeholder ="Patient Code" (ngModelChange)="ModelChange(event)" required>
</div>
<div class="col-md -3 form-group">
<input name="FirstName" [(ngModel)] ="FirstName" class="form-control" placeholder="First Name" required>
</div>
<div class=" col-md-5 form-group">
<input name="LastName" [(ngModel)]="LastName" class="form-control" placeholder="Last Name" required>
</div>
</div>
<div class="row">
<div class="form-group">
<input name="MRN" class="form-control" [(ngModel)]="MRN" placeholder="MRN" required>
</div>
<div class="col-md-3 form-group">
<!--<input name="DateOfBirth" class="form-control" placeholder="Date of Birth">-->
<ejs-datepicker name="DateOfBirth" [(ngModel)]="DateOfBirth" id='datepicker' placeholder='Enter Date Of Birth' [value]='value' [min]='minDate' [max]='maxDate'></ejs-datepicker>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button type="submit" (click)="AddPatient(p)" class="btn btn-success center-block "> Add Patient</button>
</div>
<div class="col-md-13">
<button type="submit" (click)="EditPatient(p)" class="btn btn-success center-block "> Edit Patient</button>
</div>
</div>
</form>
在控制台上出现错误,无法读取未定义的属性“控件”
请帮助我,用获取的数据设置控件属性的正确方法是什么