I am currently diving into RxJs and have set up an Observable that emits various values. However, when trying to incorporate a SetInterval for one of the values, it seems like the emission is not happening during that interval. Are there any alternative functions I should be using or could I possibly be overlooking something else?
Check out the code snippet below:
import { Observable } from 'rxjs/Observable';
import { from, interval } from 'rxjs';
var observable = Observable.create(function subscribe(observer: any) {
try {
observer.next('Hey guys!');
observer.next('How are you?');
setInterval(() => {
observer.next('I'm good');
}, 3000);
observer.complete();
observer.next('After Complete');
} catch (error) {
observer.error(error);
}
});
var timeObservable = interval(1000);
var timeSubscriber = timeObservable.subscribe((sec: any) => {
console.log(sec);
});
var observer = observable.subscribe((x: any) => addItem(x),
(error: any) => addItem(error));
function addItem(val: any) {
var node = document.createElement("li");
var textNode = document.createTextNode(val);
node.appendChild(textNode);
document.getElementById("output").appendChild(node);
}