Answer the question
In order to leave comments, you need to log in
How to take value from infinite stream during click in rxjs?
Hello.
There is 1 Observable - a click in the document and an interval. The interval starts working from the moment the page is loaded. Can you please tell me how to more elegantly take the value from the interval during the click?
So far it works like this, but I'm confused by the "extra" intermediary variable currentTime.
export class AppComponent implements OnInit {
private clickEvent$: Observable = fromEvent(document, 'click');
private timeSec$: Observable = interval(1000);
private currentTime: number;
private clickedTime: number;
ngOnInit() {
this.clickEvent$.subscribe(
_ => {
this.isClicked = true;
this.clickedTime = this.currentTime;
}
);
this.timeSec$.subscribe(intervalValue => this.currentTime = intervalValue);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question