-
Notifications
You must be signed in to change notification settings - Fork 25.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular -> generating Web Components #20859
Comments
Angular Elements is our plan, it's currently in progress |
Thats just awesome, I've found the video also: Do you have some sample project (source code) how to use it? I would love to try it. |
Nothing official atm I'm afraid. There are still some things to work out (e.g. packaging). And docs are also coming. The tl;dr instructions to use it are: import {NgModule} from '@angular/core';
// Create some component as usual. (Note: `ContentChild[ren]` are not supported.)
import {MyFunkyComponent} from './my-funky.component';
// Define a list of components that you want to use as Custom Elements. (We'll use this later.)
export const ceComponents = [MyFunkyComponent];
// Create a module (almost) as usual.
@NgModule({
...
providers: [...],
declarations: [
..., // Other non-CE components can go here
...ceComponents,
],
// Differences from what you usually do:
// - No `bootstrap` components.
// - Define as `entryComponents` all components that you want to use as Custom Elements.
entryComponents: ceComponents,
})
export class MyFunkyModule {} // Then somewhere in your non-Angular app:
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {registerAsCustomElements} from '@angular/elements';
import {ceComponents, MyFunkyModule} from './my-funky.module';
const bootstrapFn = () => platformBrowserDynamic().bootstrapModule(MyFunkyModule);
registerAsCustomElements(ceComponents, bootstrapFn).
then(moduleRef => /* Custom Elements are ready. Do your thing... */); Note, that depending on the browser you will need a different set of polyfills for Custom Elements. |
If you are interested in using ES2015 sources, there is some info in this discussion (including some working projects you can checkout). |
Thanks a lot! |
I am going to close this issue now, since it is not actionable in its current state. Feel free to fiddle around with |
I've created demo project using latest angular cli: I think more people will be interested in this topic and hope it will be useful for them. P.S. It's really simple :) |
I've created little bit more complex scenarios and results are really impressive: creating web components (source code) @gkalpak |
Thx for the feedback, @playerx! That really helps us 👍 |
I feel @angular/elements is so cool! I want to create a custom tag which is Just like Rob's demo How do I develop it by @angular/elements? |
As mentioned above, there are still some rough edges and packaging is an open issue. In a nutshell, you would need to bundle your Angular app (including Angular itself and any 3rd-party libs) and run |
@gkalpak Thank you for quick reply ! And I see. I have one more question.
export function registerAsCustomElements<T>(
customElementComponents: Type<any>[], platformRef: PlatformRef,
moduleFactory: NgModuleFactory<T>): Promise<NgModuleRef<T>>;
export function registerAsCustomElements<T>(
customElementComponents: Type<any>[],
bootstrapFn: () => Promise<NgModuleRef<T>>): Promise<NgModuleRef<T>>; How should we use each two funcitons differently? |
@gkalpak |
@gogakoreli not every component has angular inside, angular runtime will be per project you create and in project you can have multiple web components. If you will create projects for each component it will have overhead I think. It will be interesting to make some experiments with https://nrwl.io/nx, here you will have same versions of packages and you will not need to download angular runtime per project, but I don't know how it will work in real life, yet |
Lets take we have different angular web components and they have dependency on the same versions of packages, which are angular or any third party packages. Can these components share same dependencies between them in the same app environment? I am talking about angular web components which are developed independently, located inside different projects. |
@gogakoreli, we still need to figure this stuff out (and work is in progress for being able to make the components as slim as possible). As @playerx mentioned, you can have multiple components (or even Theoretically, in the simple case where you have multiple projects using the same version, you should be able to load Angular once, create a It is pretty much uncharted territory, but we are very eager to explore it 😃 |
I've created a blog post about angular elements and my researches: Hope it will help new users to get started with Angular Elements :) |
Interesting example, how to use Angular Elements: |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
none
Expected behavior
Create web components using angular
What is the motivation / use case for changing the behavior?
I think it would be cool if angular will give us ability to generate web components, I was researching and found angular elements project but it's archived: https://github.com/robwormald/angular-elements.
Main goal is to generated web components, that will wrap angular component and will be hosted & accessible independently.
What's your plan about that?
The text was updated successfully, but these errors were encountered: