is there an equivalent of async pipe that you can use inside a component?

前端 未结 4 935
离开以前
离开以前 2021-02-13 03:52

Does there exist something equivalent to the async pipe that I could use inside a component like this

   @Component({
      selector: \'my-component         


        
4条回答
  •  别跟我提以往
    2021-02-13 04:54

    The only way you can your goal (not using subscription) is to use BehaviorSubject, it has a method getValue(). There are some differences between Observables and BehaviousSubjects (you can find them in documentation).

    var subject = new Rx.BehaviorSubject(current_subject_value);
    subject.getValue()
    

    Yet there are some stackoverflow debates why shoudnd't you use getValue method, but rather to use subscription... Yet there is observable take operator which will complete observable sequence (thus don't have to manage subscriptions)

    this.myObservable$.take(1).subscribe()
    

提交回复
热议问题