How to use subscribe-next RxJS in Angular?

Viewed 4522

I am learning rxjs. I have an observable from an array. I want to put some fruit in function, using subscribe and next. I wrote but not right, may I help you. Thank you so much!

const fruits = from([
    "apple",
    "banana",
    "cherry"]);

fruits.subscribe(fruit => this.next(fruit));
1 Answers
const myObserver = {
  next: (item) => console.log('next: ', item),
  error: (err) => console.log('err: ', err),
  complete: () => console.log("Observable completed")
};

of([
  "apple",
  "banana",
  "cherry"
]).subscribe(myObserver);

setTimeout(() => myObserver.next(["Apple"]) ,2000);

Answer to Your exercise :D

fruits.subscribe(fruit => toConveyorBelt(fruit));
Related