question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use component templating without a module

See original GitHub issue

I have been looking for the capability to use Angular strictly as a component/template renderer. I don’t need it to compile into customElements, I just need to mount a component instance on a DOM element and pass in dependencies using simple property injection.

Basic syntax example

import { Component } from '@angular/core';

@Component({
  selector: 'app-home',
  declarations: [ pipes, directives, components ],
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css'],
})
class HomeComponent {
    constructor(
        public dependencyA: any,
        private dependencyB: any
     ) {}
}

const target = document.querySelector('#component-root')

const component = new HomeComponent()
const instance = component.mount(target, [dependencyA, dependencyB]) 
  .subscribe(mountEvent => console.log(mountEvent))

instance.unmount()
  .subscribe(mountEvent  => mountEvent )

Perhaps if the injector is omitted and an array supplied, elect to use property injection, where passing an injector will enable usage of the dependency injection framework.

component.mount(target, [dependencyA, dependencyB]) 
component.mount(target, { injector }) 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
JoostKcommented, May 3, 2019

I think @robwormald’s presentation during ng-conf last Wednesday may be interesting to you, as it touches some of the ideas you mention in the description.

0reactions
angular-automatic-lock-bot[bot]commented, Apr 28, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to use Angular components without Angular ...
So no. Only if you declare your components in one main module. ... You don't have to use modules anymore since components can...
Read more >
How to create page only with modules and no component?
templates, you can set up an additional template using layout b. Go to your home menu item, select that template. The component won't...
Read more >
Introduction to components and templates - Angular
A component controls a patch of screen called a view. It consists of a TypeScript class, an HTML template, and a CSS style...
Read more >
How to create a Native Web Component without a Framework
Learn how to create a native Web Component without using a framework; Explanation of all steps and essentials points like HTML Templates, ...
Read more >
Build for production - Lit.dev
When building an app that includes LitElement components, you can use common ... Bare module specifiers let you import modules without knowing exactly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found