Giter Club home page Giter Club logo

micro-frontend-project's Introduction

MicroFrontendProject

Angular library that allows easy communication between iframes. Designed for the development of micro frontends.

Run example project

Run npm i to install dependencies.

Run npm run build micro-frontend to build de library.

Run ng serve --port 4200 to serve father project

Run ng serve --port 4201 to serve child project

Run ng serve --port 4202 to serve father2-child2 project

Run ng serve --port 4203 to serve child3 project

Navigate to http://localhost:4200/

Example project explanation

In this example we have 4 angular projects running on different URLs.

The project is configured to act as parent (4200), parent's child (4201), parent child with it's own child (parent 2) (4202) and parent 2's child.

In this example we use library through MicroFrontendComponent to see some capabilities.

Micro frontends load in their respective iframes.

The parent can send a message to his children.

It is also possible to send a message to a specific child.

Children can send a message to their parents.

It is also possible to send a message to a specific parent.

In this case we have a child that is also a parent of its own child and they can communicate in the same way with each other.

Finally we have the option of sharing global information with the whole family at different levels of relationship (grandparents, children, grandchildren...)

Install dependency

npm i @rgarciadelongoria/micro-frontend

Setting up parent.

<iframe #child src="http://localhost:4201" name="child"></iframe>
@ViewChild('child') iframeChild!: ElementRef;

constructor(private microFrontendSrv: MicroFrontendService) { }

ngOnInit(): void {
    this.microFrontendSrv.init();
    this.microFrontendSrv.getOnMessageObservable().subscribe((message: any) => {
        // Do something with the received message
    });
}

ngAfterViewInit(): void {
    this.microFrontendLibComponent.addMicroFrontend({elementRef: this.iframeChild});
}

Setting up child.

constructor(private microFrontendSrv: MicroFrontendService) { }

ngOnInit(): void {
    this.microFrontendSrv.init(['http://localhost:4200']);
    this.microFrontendSrv.getOnMessageObservable().subscribe((message: any) => {
        // Do something with the received message
    });
}

Methods.

Coming soon

micro-frontend-project's People

Contributors

rgarciadelongoria avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.