0
votes
//example 1
const xd = new Observable(({ next }) => {
  next("3");
});

xd.subscribe(msg => console.log(msg));

//example 2
    const obs$ = new Observable();

    obs$.subscribe(mg => console.log(mg));

//example 3
 private socket: SocketIOClient.Socket;
  constructor(private url: string) {
    this.socket = io(this.url);
  }

  listen() {
    return new Observable(({ next }) => {
      this.socket.on("message", next)
    })
  }

They are all giving me the same error, what might have gone wrong ?

(Uncaught TypeError: Cannot read property 'isStopped' of undefined)

1

1 Answers

2
votes

Use like this,

const xd = new Observable((observer) => {
  // observable execution
  observer.next("3");
});

xd.subscribe(msg =>{
   console.log(msg)
},
(error)=>{
  console.error(error);
}
);