【发布时间】:2021-03-06 04:16:52
【问题描述】:
Parent.component.html
<app-child [activeUser]="activeUser" *ngIf="eceConfirm && activeUser"></app-child>
Parent.component.ts 在 ngOnInit 中,我调用 getAllEmployees 来获取所有员工数据,并使用 @Input() activeUser 将第 0 个索引数据传递给子组件。
getAllEmployees() {
this.service
.getCommonEmployeesDetail(this.user["uid"], this.selectedRatingCycleId)
.subscribe((res) => {
this.userList = res;
this.changeUser(this.userList[0]);
});
}
changeUser(user) {
console.log("user", user);
this.activeUser=user;
}
Child.component.ts
我已经在我的子组件中实现了 changeDetection.Onpush 策略。 获取我的 activeUser 数据后,我将其传递给 changeChildUser() 方法以从请求中获取数据并将其分配给 this.cycleData。
我面临的问题 1.当我尝试在 HTML 页面中打印 {{cycleData.Englishmarks}} 时不会刷新。我安慰了 this.cycleData,它在控制台中显示了值。
任何想法可能是什么问题。任何输入表示赞赏。在此先感谢
@Input() activeUser: BpuData;
ngOnChanges(changes: SimpleChanges) {
this.changeChildUser();
}
changeChildUser() {
this.chapterService.getcycle(this.activeUser).subscribe(response =>{
this.cycleData=response;
});
}
【问题讨论】:
-
使用异步管道。尽量避免使用
subscribe,因为您不必记得退订。仅供参考,您这里有内存泄漏。
标签: angular typescript