Please note that this question is NOT about regular Angular components. I'm specifically asking about a reusable custom element created with Angular also called an Angular web component.
I have a reusable Angular 10 web component being hosted inside another Angular 10 web app. Using attribute names that are dash-separated lowercase(i.e. my-data), I'm able to input a string to an Angular web component that has an @Input with lower camel case(i.e. myData).
HOST APP has the following in it's markup:
<my-custom-element my-data="test"></my-custom-element>
REUSABLE WEB COMPONENT - my-custom-element:
@Input() myData: string;
The string works fine and does get passed into the web component. Now, how do I pass an observable to the web component? Example (this does not work as it is taking what's inside the "" as a literal string.)
HOST APP MARKUP:
<my-custom-element
my-data="test"
fetch-event="eventsSubject.asObservable()"
></my-custom-element>
HOST APP COMPONENT:
eventsSubject: Subject<void> = new Subject<void>();
handleButtonClick(event: any): void {
this.eventsSubject.next();
}
REUSABLE WEB COMPONENT - my-custom-element:
@Input() myData: string;
@Input() fetchEvent: Observable<void>;
I also tried the following which also doesn't work: [fetch-event]="eventsSubject.asObservable()"
If using @Input to pass in an observable to Angular web components is not the way to do it, please let me know. I also tried this.elRef.nativeElement.attributes['fetchEvent'].value which also didn't work for me.