这是.html代码
<div class="box col-lg-3 sidebar col-3">
<ul style="overflow-x: hidden; overflow-y:scroll">
<ng-container *ngFor="let user of products" [class.selected]="user === selectedPatient" >
<li *ngIf="filter(user)" (click)="onSelect(user);" >
<p>{{ user.name }} {{ filtername }}</p>
</li>
</ng-container>
</ul>
</div>
<div class="box col-lg-9 mainpage col-9 " style="padding:0px;">
<app-doctor-patientview [patient]="selectedPatient" ></app-doctor-patientview>
<!-- -->
</div>
这是上述html代码的component.ts代码
products: any[];
name: any;
selectedPatient: Patient;
filtername: string="";
show:boolean = true;
onSelect(hero: Patient): void {
this.selectedPatient = hero;
console.log(this.selectedPatient);
}
filter(patient : Patient) : boolean{
if (patient.name.toUpperCase().indexOf(this.filtername.toUpperCase())>-1){
return true;
}
return false;
}
这是app-doctor-patientview.html
<div *ngIf="patient"></div>
app-doctor-patientview component.ts的代码段
export class DoctorPatientviewComponent implements OnInit {
@Input() patient: Patient;
isOn=1;
constructor() { }
ngOnInit() {
}
}
似乎在.html代码中包含* ngIf时,selectedPatient参数没有传递给app-doctor- Patientview。
如果我不包括* ng如果参数通过并且在app-doctor- Patientview中正确显示。我该如何解决这个错误?