Skip to content

Modus-Logo-Long-BlackCreated with Sketch.

  • Services
  • Work
  • Blog
  • Resources

    OUR RESOURCES

    Innovation Podcast

    Explore transformative innovation with industry leaders.

    Guides & Playbooks

    Implement leading digital innovation with our strategic guides.

    Practical guide to building an effective AI strategy
  • Who we are

    Our story

    Learn about our values, vision, and commitment to client success.

    Open Source

    Discover how we contribute to and benefit from the global open source ecosystem.

    Careers

    Join our dynamic team and shape the future of digital transformation.

    How we built our unique culture
  • Let's talk
  • EN
  • FR

Angular Elements — Your ngComponents Everywhere

Published on November 6, 2017
Last Updated on April 8, 2021
Application Development

If you’re reading this, you already know Angular. So whether you’ve worked on AngularJS (1.x) or Angular (Angular2+), this article is about one of the exciting things going on in the Angular world.

Angular has been one of the most popular frameworks for the past few years. It started as a library that enhanced HTML. And now it has a huge ecosystem that contains CLI, Server side rendering, Animations, etc, and it is still growing with things like Angular service worker. While these are making Angular awesome, there are some experimental projects in the ecosystem which are exciting.

Team Angular announced a new idea called Angular Labs during their recent conference at Angular Mix. The idea of Angular Labs is to keep the community in sync about new experiments before releasing them to the public (that’s an Angular thing for sure). There are four initiatives that fall under the hood of Angular Labs to date:

  1. Schematics
  2. Angular Elements
  3. CDK (Component Dev Kit)
  4. ABC (Angular + Bazel + Closure)

While all of these are exciting, I’ll go with Angular Elements for this article.

What are Angular Elements?

Angular Elements are Custom Elements. You can embed them into any web application. This enables us to write re-usable Angular components & widgets which we can use inside React, Vue, Preact or even with vanilla JS apps. The Angular Elements will blend in every framework. Below are some features of Angular Elements:

  • They are Self Bootstrapping.
  • They actually host the Angular Component inside a Custom Element.
  • They’re a bridge between the DOM APIs and Angular Components.
  • Anyone can use it without having the knowledge of how Angular works.

How to create an Angular Element

You can follow these steps to create your Angular Elements

  • Fork (or clone) angular-elements repo
  • Create your widget/app folder inside src/demos folder (e.g. test-app )
  • Create your app’s module (e.g. TestAppModule -> test-app.module.ts)
  • Create your component (e.g. TestComponent -> test.component.ts)
  • Once your app is completed, run the webpack build to generate ngfactory files for your app by running the below command:
    npm run build
  • Use the custom_element_adapter to generate your Angular Element in your demo folder (e.g. src/demos/test-app with your ng-element named test-app.ngelement.ts )
    import nge from `../../custom_element_adapter`;
    import { TestAppNgFactory } from '../../ngfactory/src/demos/test-app/test-app.ngfactory';
    nge.define( TestAppNgFactory ); 
  • After that, add your demo as an entry inside webpack.config.js as follows:
    entry: {
     'todo-app': './lib/demos/todo-app/todo-app.ngelement.js',
     ..
     'test-app': './lib/demos/test-app/test-app.ngelement.js'
    } 
  • You can then create an HTML file in the public folder (e.g. test-app.html ) having content as follows:
    <html>
       <head>
           <meta charset="UTF-8">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
           <meta http-equiv="X-UA-Compatible" content="ie=edge">
           <title>Ng Elements Playground - Test App</title>
           <script src="es5-shim.js"></script>
           <script src="angular.js"></script>
           <script src="test-app.js" async></script>
       </head>
       <body>
           <test-app></test-app>
       </body>
    </html> 

I also added a demo app (Stop Watch App) and created a PR against the angular-elements repository.

Conclusion

I liked the flexibility and possibilities Angular Elements are bringing to the table, even though they are not ready to use right away. I hope we’ll see Angular Elements being stable in a few months.

Please share this article with anyone who might enjoy it. You may star the repos (Angular Elements, Angular Elements Demos) or contribute to them too. Find me on Twitter, or comment below, and let me know how this worked out for you.

Posted in Application Development
Share this

Ahsan Ayaz

Ahsan Ayaz is a Google Developer Expert in Angular. During his time at Modus, Ahsan worked as a Software Architect. Apart from building web and hybird-mobile apps based on Angular, Ionic & MEAN Stack, Ahsan contributes to open-source projects, speaks at events, writes articles and makes video tutorials.
Follow

Related Posts

  • What-Promises-Do-That-Observables-Cant
    What Angular Promises Do That Angular Observables Can't

    Nothing. Observables are grabbing the spotlight as one of the cool new things Angular 2…

  • Accessing Child Elements in Angular / Ionic
    Accessing Child Elements in Angular / Ionic

    Components are at the heart of Angular, and we have some very useful tools to…

Want more insights to fuel your innovation efforts?

Sign up to receive our monthly newsletter and exclusive content about digital transformation and product development.

What we do

Our services
AI and data
Product development
Design and UX
IT modernization
Platform and MLOps
Developer experience
Security

Our partners
Atlassian
AWS
GitHub
Other partners

Who we are

Our story
Careers
Open source

Our work

Our case studies

Our resources

Blog
Innovation podcast
Guides & playbooks

Connect with us

Get monthly insights on AI adoption

© 2025 Modus Create, LLC

Privacy PolicySitemap
Scroll To Top
  • Services
  • Work
  • Blog
  • Resources
    • Innovation Podcast
    • Guides & Playbooks
  • Who we are
    • Our story
    • Careers
  • Let’s talk
  • EN
  • FR