Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active Mar 30, 2018
Embed
What would you like to do?
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements';
import { NgModule, Injector, NgModuleFactory, NgModuleRef } from '@angular/core';
import { SomeService } from './service'
import { AppComponent } from './app.component';
import { DemoElementModule, DemoElement } from './demo-element'
import { DemoElementModuleNgFactory } from './demo-element.ngfactory'
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [SomeService],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(private injector:Injector){
const elementsModuleInstance:NgModuleRef<DemoElementModule> = DemoElementModuleNgFactory.create(injector);
console.log(elementsModuleInstance);
const ElCtor = createCustomElement(DemoElement, {injector: elementsModuleInstance.injector });
customElements.define('my-el', ElCtor);
}
ngDoBootstrap(){
}
}
import { BrowserModule } from '@angular/platform-browser';
import { createCustomElement } from '@angular/elements';
import { NgModule, Injector, NgModuleFactory, NgModuleRef } from '@angular/core';
import { SomeService } from './service'
import { AppComponent } from './app.component';
import { DemoElementModule, DemoElement } from './demo-element'
import { DemoElementModuleNgFactory } from './demo-element.ngfactory'
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [SomeService],
//bootstrap: [AppComponent]
})
export class AppModule {
constructor(private injector:Injector){
const elementsModuleInstance:NgModuleRef<DemoElementModule> = DemoElementModuleNgFactory.create(injector);
console.log(elementsModuleInstance);
const ElCtor = createCustomElement(DemoElement, {injector: elementsModuleInstance.injector });
customElements.define('my-el', ElCtor);
}
ngDoBootstrap(applicationRef:ApplicationRef){
applicationRef.bootstrap(SomeComponent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment