Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Module-Federation: How to addEventListener in Shell app for MFEs App Angular element web components

I am using Angular v14.1.1 and @angular-architects/module-federation v14. And In MFEs using Angular elements createCustomElement and exposes as ./web-component using @angular-architects/module-federation webpack config. From MFEs app emit event but not getting how to add MFEs listener in shell application to listen event.

for example

MFEs App

App.module.ts

export class AppModule implements DoBootstrap
{
  constructor(private injector: Injector) { }
  ngDoBootstrap(): void {
    if (!customElements.get('angular14-customer')) {
      customElements.define(
        'angular14-customer',
        createCustomElement(MFEComponent, { injector: this.injector })
      );
    }
  }
 }

Shell App

AppRoutingModule ts

import { WebComponentWrapper, WebComponentWrapperOptions } from '@angular-architects/module-federation-tools';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [ 
{
  path: 'angular14',
  component: WebComponentWrapper,
  data: {
    type:'module',
    remoteEntry: 'http://localhost:4201/remoteEntry.js',
    exposedModule: './web-components',
    elementName: 'angular14-customer'
  } as WebComponentWrapperOptions
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

For example MFEs Component Event:

@Output() saveRecord: EventEmitter<any> = new EventEmitter<any>();

MFESaveClick(response){
 this.saveRecord.emit(response);
}

How to add Event Listener in Shell app for MFES Events?

Please let me know if any other detail required.

please advise.

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Not sure about exact solution but I think there is way using web-components Input/Output @angular-architects/module-federation-tools as Directly Loading a Web Component via Module Federation menintion here in docs.

In shell app creating custom component and route to path by imports ModuleFederationToolsModule.

const routes: Routes = [
  {
     path:'angular14',
     component: CustomerComponent  
  },
  {
    path:'**',component:NotFoundComponent
  }
  ];
@NgModule({
  declarations: [
    AppComponent,
    CustomerComponent,
    NotFoundComponent
  ],
  imports: [
    BrowserModule,
    CommonModule,
   RouterModule.forRoot(routes),
    ModuleFederationToolsModule
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas:[]
})
export class AppModule { }

And then in CustomerComponent using WebComponentWrapper selector.

for example

<mft-wc-wrapper [options]="options" [props]="props" [events]="events"></mft-wc-wrapper>
import { WebComponentWrapper, WebComponentWrapperOptions } from '@angular-architects/module-federation-tools';
import { Component } from '@angular/core';

@Component({
  selector: 'app-customer',
  templateUrl: './customer.component.html'
})
export class CustomerComponent {
  title = 'CustomerComponent';
  props = {
    "message": "Hello from Shell"
}

events = {
    "saveRecord": (event:any) => {
        console.debug('saveRecord!', event);
    }
}
  options: WebComponentWrapperOptions = {
    type:'module',
    remoteEntry: 'http://localhost:4201/remoteEntry.js',
    exposedModule: './web-components',
    elementName: 'angular14-customer'
  };
}

And remote app you can use props and events something like this.

<!--MFEComponent-->
remote app!
<button (click)="MFESaveClick($event)">click me !</button>
//MFEComponent
 
  @Output() saveRecord: EventEmitter<any>
  = new EventEmitter<any>();

  @Input() message:any;
   

  MFESaveClick(response){
 this.saveRecord.emit(response);
 }

Not tested, but hope this will help.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda