This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AngularCustomElementBridge { | |
prepare(injector, component) { | |
this.componentFactory = injector.get(ComponentFactoryResolver).resolveComponentFactory(component); | |
// we use templateName to handle this case @Input('aliasName'); | |
this.observedAttributes = componentFactory.inputs.map(input => input.templateName); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AngularCustomElementBridge { | |
setInputValue(propName, value) { | |
if (!this.componentRef) { | |
this.initialInputValues[propName] = value; | |
return; | |
} | |
if (this.componentRef[propName] === value) { | |
return; | |
} | |
this.componentRef[propName] = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AngularCustomElementBridge { | |
destroy() { | |
this.componentRef.destroy(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AngularCustomElementBridge { | |
initComponent(element: HTMLElement) { | |
// first we need an componentInjector to initialize the component. | |
// here the injector is from outside of Custom Element, user can register some of their own | |
// providers in it. | |
const componentInjector = Injector.create([], this.injector); | |
this.componentRef = this.componentFactory.create(componentInjector, null, element); | |
// Then we need to check whether we need to initialize value of component's input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.componentFactory = injector.get(ComponentFactoryResolver).resolveComponentFactory(component); | |
this.observedAttributes = componentFactory.inputs.map(input => input.templateName); // we use templateName to handle this case @Input('aliasName'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callback | summary | angular part | |
---|---|---|---|
constructor | initialize internalstate | do some preparation work | |
connectedCallback | initialize View/Event Listener | Load Angular Component | |
disconnectedCallback | clear View/Event Listener | Destroy Angular Component | |
attributeChangedCallback | Handle attribute change | Handle @Input Change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelloComponentClass extends HTMLElement { | |
constructor() { | |
super(); | |
} | |
static get observedAttributes() { | |
} | |
connectedCallback() { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Input } from '@angular/core'; | |
@Component({ | |
selector: 'app-hello', | |
template: `<div>{{name}}</div>` | |
}) | |
export class HelloComponent { | |
@Input() name: string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
callback | summary | |
---|---|---|
constructor | initialize state or shadowRoot if needed | |
connectedCallback | Will be called when element is added to DOM | |
disconnctedCallback | Will be called when element is removed from DOM | |
attributeChangedCallback | Will be called when attribute of the element change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppHello extends HTMLElement { | |
constructor() { | |
super(); | |
} | |
// define which attributes need to be observed so attributeChangedCallback will be triggered | |
// when according attribute changed. | |
static get observedAttributes() {return ['name']; } | |
// getter to do a attribute -> property reflection |