I am getting a weird error when trying to subscribe to an Observable.
Here is a watered down version of the code which presents the problem:
The problem is the lifecycle hook you're using. The element is not yet creating in DOM when ngOnInit
is called. Instead, you should use ngAfterViewInit
.
Could you try the following code:
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { Observable, fromEvent } from 'rxjs';
@Component({
template: ''
})
export class ActionOverviewDescription implements AfterViewInit {
@ViewChild('input') button: ElementRef;
ngAfterViewInit() {
let buttonStream$ = Observable.fromEvent(this.button.nativeElement, 'click')
.subscribe(res => console.log(res));
}
}