简体   繁体   English

如何使用 Angular 9 中的“延迟加载”使用子组件的事件属性绑定父组件

[英]How to bind parent component using child component's event property using `lazy loading` in Angular 9

I am converting some components to be lazily loaded using the ivy compiler in Angular 9.我正在使用 Angular 9 中的ivy compiler将一些组件转换为lazily loaded

This is my code at the moment:这是我目前的代码:

<bulk-user-upload [visible]="bulkUserUploadVisible (fileUploaded)="onBulkUserUploadFileUploaded($event)">

and I am trying to modify the code become like this:我试图修改代码变成这样:

<ng-container #bulkUserUpload></ng-container>

I want to access the fileUploaded function that exists in the child component so I can listen the event on the parent component.我想访问子组件中存在的fileUploaded函数,以便我可以监听父组件上的事件。

const { BulkUserUploadComponent } = await import('../bulk-user-upload/bulk-user-upload.component');
const bulkUserUploadFactory = this.cfr.resolveComponentFactory(BulkUserUploadComponent);
const { instance } = this.bulkUserUploadContainer.createComponent(bulkUserUploadFactory, null, this.injector);

instance.visible = true;

How do I modify the code above so that I can access child the function?如何修改上面的代码以便我可以访问子函数?

So I added this to my parent component所以我将它添加到我的父组件中

instance.fileUploaded.pipe(
      takeUntil(instance.destroy$)
    ).subscribe(resp => this.onBulkUserUploadFileUploaded(resp));

and this to the child destroy$ = new Subject();这给孩子destroy$ = new Subject();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ngSwitch的Angular 2+中将事件从子级绑定到父级组件 - How to bind event from child to parent component in Angular 2+ in ngSwitch 当父组件不使用子组件选择器时,如何将数据从子组件传递到Angular6中的父组件? - How to pass data from child to parent component in Angular6 when parent component not using child's component selector? 在 Angular 中使用子组件的属性? - Property using child component in Angular? Angular 6使用懒惰laoding访问父组件的子组件时发生意外行为 - Angular 6 Unexpected behavior when getting access to child component of a parent component using lazy laoding Angular 2 @Input - 如何从父组件绑定子组件的 ID 属性? - Angular 2 @Input - How to bind ID property of child component from parent component? 如何使用 angular 中的按钮单击事件将单个属性从父组件发送到子组件 - How can i send the single property from parent component to child component with button click event in angular 在Angular 2中加载子组件时如何隐藏父组件 - How to hide the parent component when loading a child component in Angular 2 如何从 Angular 中的子组件修改父组件的 css 属性 - How to modify parent component's css property from child component in Angular Angular2中的子级属性更改时更新父级属性(使用路由出口加载的子级组件) - Update Parent Property When Child Property Changes in Angular2 ( Child component loaded using router-outlet) 使用父组件中的click事件,子组件中的Angular2 Toggle类 - Angular2 Toggle Class in child component using a click event in parent component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM