Skip to content

Commit

Permalink
fix(module:lazy-targ-comp): 修复onchange狗子无法监听的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huajian123 committed Feb 19, 2023
1 parent 96f2245 commit 4ab71dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/app/pages/comp/lazy/lazy-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ export class LazyServiceService {
async lazyLoadCard(selPerson: LazySelPeopleEnum = LazySelPeopleEnum.YiLin): Promise<void> {
const viewContainerRef = this._adHost.viewContainerRef;
const { LazyTargCompComponent } = await import('./lazy-targ-comp/lazy-targ-comp.component');
const { instance } = viewContainerRef.createComponent(LazyTargCompComponent);
instance.purChoosePeople = selPerson;
instance.currentPeople.pipe(takeUntil(instance.destroy$)).subscribe(() => {
this.create(instance.purChoosePeople);
const componentRef = viewContainerRef.createComponent(LazyTargCompComponent);
// 使用setInput api可以被onchange钩子管理
componentRef.setInput('purChoosePeople', selPerson);
componentRef.instance.currentPeople.pipe(takeUntil(componentRef.instance.destroy$)).subscribe(() => {
this.create(componentRef.instance.purChoosePeople);
});
// 实现OnChange钩子
(instance as any).ngOnChanges({
purChoosePeople: new SimpleChange(null, instance.purChoosePeople, true)
});
// (instance as any).ngOnChanges({
// purChoosePeople: new SimpleChange(null, instance.purChoosePeople, true)
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export class LazyTargCompComponent implements OnInit, OnChanges {

ngOnInit(): void {}

ngOnChanges(changes: SimpleChanges): void {}
ngOnChanges(changes: SimpleChanges): void {
console.log(changes);
}
}

@NgModule({
Expand Down

0 comments on commit 4ab71dc

Please sign in to comment.