Use component templating without a module
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.