简体   繁体   中英

How to call a method of an observable in angular?

I'm trying to call a business method after subscribe to an observable with rxjs but I cannot make it work. What I'm missing?

observable$.subscribe(value: A => {
  value.businessMethod();
});
class A {

  public businessMethod(): number {
    ...
  }
}

ERROR TypeError: "value.businessMethod is not a function"

I guess the error occurs when obervable$ does not hold a value yet. Its value is undefined. Please try

observable$.pipe(
  filter(Boolean),
).subscribe(value: A => {
  value.businessMethod();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM