I have a project generated with @angular/cli v7.0.3.
I've pushed a small demo application here: https://github.com/collinstevens/web-component-sender
I have added @angular/elements and the @webcomponents/webcomponentsjs polyfill.
I have a basic Angular component, AppComponent, and a web component built using @angular/element defined in the AppModule constructor using ReceiverComponent as the Angular component and web-receiver as the web component tag.
I expect when I type into the AppComponent it will update the AppComponent and the ReceiverComponent with the updated value.
Currently, only the AppComponent is receiving the updated value, while the ReceiverComponent will display only the initial value set in the AppComponent.
Given https://angular.io/guide/elements#mapping, the myValue Input() on ReceiverComponent should be mapped as my-value.
AppComponent
export class AppComponent {
value = '';
}
<div>
<span>Angular Component Input:</span>
<input [(ngModel)]="value">
</div>
<div>
<span>Angular Component Span:</span>
<span>{{value}}</span>
</div>
<div>
<span>Web Component Span</span>
<web-receiver [my-value]="value"></web-receiver>
</div>
ReceiverComponent
export class ReceiverComponent {
@Input()
myValue: string | undefined = undefined;
}
<span>{{myValue}}</span>
AppModule
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent, ReceiverComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent],
entryComponents: [ReceiverComponent]
})
export class AppModule {
constructor(private injector: Injector) {
const senderElement = createCustomElement(ReceiverComponent, {
injector: this.injector
});
customElements.define('web-receiver', senderElement);
}
}