-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.component.ts
49 lines (44 loc) · 1.55 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {
LoadRemoteModuleOptions,
loadRemoteModule,
} from '@angular-architects/module-federation';
import {
Component,
OnInit,
VERSION,
} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
public readonly version: string = VERSION.full;
public message: string = "";
public async ngOnInit(): Promise<void> {
const loadRemoteWebpackModuleOptions: LoadRemoteModuleOptions = {
type: 'module',
exposedModule: './standalone-component-as-web-component',
remoteEntry: 'http://localhost:4201/remoteEntry.js',
};
const webpackModule: any = await loadRemoteModule(loadRemoteWebpackModuleOptions);
await webpackModule.bootstrapMyComponentAsync();
};
// Without the /src/app/mfe1.d.ts type declaration file the handler for the
// 'message-sent' event must have an input of type Event and then you need
// to cast it to CustomEvent<string>.
//
// With the /src/app/mfe1.d.ts type declaration file you can subscribe
// to the 'message-sent' event and take in the type CustomEvent<string>
// as the input. Like this:
//
// public onMessageSent(event: CustomEvent<string>): void {
// this.message = event.detail;
// }
//
// Comment the 'onMessageSent(event: Event)' method below and uncomment the
// 'onMessageSent(event: CustomEvent<string>)' method above to test it out.
public onMessageSent(event: Event): void {
this.message = (event as CustomEvent<string>).detail;
}
}