티스토리 뷰

async파이프는 당신을 위해 가입을 처리합니다. 구독을 수동으로 수행하려는 경우 언제든지 Observable에 구독하고 직접 변수 업데이트를 처리 할 수 ​​있습니다.

데모는이 plnkr을 참조하십시오 .

관련 코드 :

import {Observable} from 'rxjs/Observable';

import "rxjs/add/observable/interval";

@Component({
  selector: 'my-app',
    template: `
        <div>
              <p>Counter with async: {{ counter | async }}</p>
                    <p>Counter without async: {{ subscribedCounter }}</p>
                        </div>
                          `,
                          })
                          export class App {
                            counter: Observable<number>;
                              subscribedCounter: number;
                                constructor() {
                                    this.counter = Observable.interval(1000);
                                        this.counter.subscribe(
                                              v => { this.subscribedCounter = v; }
                                                  );
                                                    }
                                                    }
                                                    
-------------------

내 대답 ...

Promise에서 데이터를 가져 오지만 두 구성 요소간에 공유되는 변수를 서비스에서 어떻게 만들 수 있습니까?

... (업데이트 된 질문에서) 수행하려는 작업의 기본 예를 다룹니다.



출처
https://stackoverflow.com/questions/39940109
댓글
공지사항
Total
Today
Yesterday
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31