angular - 由于 ngIf,参数未通过
问题描述
这是 .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。
如果我不包含 *ngIf 参数通过并在 app-doctor-patientview 中正确显示。我该如何解决这个错误?
解决方案
推荐阅读
- java - 使用 Spark 从 HDFS 到 Oracle BLOB 的 CSV 文件
- javascript - 无论在调用者上配置 catch 子句,都承诺拒绝
- jenkins - HTTP ERROR 404 Jenkins 仅提供此域上的静态文件
- java - 在 ImageView 中显示来自 MySQL 的原始 PNG
- python - 如何在 python 的 __init__() 构造函数中传递 **kwargs?
- python - Okapi BM25在python中的实现
- html - removeClass() 的问题
- delphi - 我可以向 Firemonkey 中的组件添加第二个组件编辑器吗?
- java - 如何使用 Spring Boot 打包 React 前端并运行可执行 jar?
- swift - 如何解决此错误并安装 cocoapods?