i make a small angular application and convert it into angular element to use it as a micro frontend in other master App and it looks great and works fine. but I need to pass a value from Master App to the Micro App but didn't work with me. can anyone help with this issue.
Micro Application app.module.ts
export class AppModule {
constructor(private injector: Injector) { }
ngDoBootstrap(){
const element = createCustomElement(AppComponent, {injector: this.injector});
customElements.define('micro-fe', element);
}
}
Micro Application app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'Micro-FE';
@Input() public myName: string = "";
ngOnInit() {
console.log(this.myName);
}
}
Micro Application app.component.html
<h1>Hello From Micro-Frontend !!!!!</h1>
<h2>My Name : {{myName}}</h2>
and in the Master Application index.html
<!doctype html>
<html lang="en">
<body>
<app-root></app-root>
<micro-fe myName="Amr"></micro-fe>
<script src="assets/Micro-FE/main.js"></script>
<script src="assets/Micro-FE/polyfills.js"></script>
<script src="assets/Micro-FE/runtime.js"></script>
</body>
</html>
window.dispatchEvent()), and listening to the events on app B (fromEvent(window, '...').subscribe()). Here is an article