Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared data between Angular Elements

I'm look into Angular Elements and thinking of generate our Angular Components into Angular Elements to make it possible to be used outside Angular applications.

Let's say I got a Angular 4 app which imports two different Angular Elements (built in Angular 7) and render them on the same page and I instantiate a service in my Angular 4 component. That service contains data that I want to pass into my Angular Elements, since web components only accepts strings as attributes (inputs), is there any good way for sharing data between/pass the instance of the service into the Angular Elements?

like image 365
bjorkblom Avatar asked Nov 21 '18 18:11

bjorkblom


People also ask

How many ways we can share data in Angular?

There are five ways to share data between components: Parent to child component. Child to parent component. Sharing data between sibling components.

Can we send data from one component to another in Angular?

When we build components in an application, we maybe need to share or send data from parent to child or without a direct connection. Angular provides different these ways to communicate components: Using Input() and Output() decorators. Using Viewchild decorator.


1 Answers

According to the latests talks on angular elements you will be able to pass in an injector when creating the element.

This shared injector will then act as the bridge between the different elements.

like image 82
Leon Radley Avatar answered Sep 20 '22 11:09

Leon Radley