Sorry if this is a silly question.
I am looking at the following code snippet:
ngOnInit(): void {
let data$ = new Observable((observer: Observer<string>) => {
observer.next('message 1');
});
data$.subscribe(s => console.log(s));
}
I can see that 'message 1' is being displayed in the console output. I am confused about when and how observer.next is being called.
I have declared the variable data$
which holds an Observable object. But I am not sure why the observer.next method is being triggered automatically.