2016-07-06 209 views
1

我在angular2下面的代碼框架(TS):Angular2管理嵌套訂閱

a() { 
    return callService1.do(
    z => { 
     callService2.subscribe(y => console.log("a callService2")) 
     console.log("callService1") 
    } 
) 
} 


b() { 
    a.subscribe(
    x => console.log("b subscribe callService1") 
    ) 
} 

結果,我有:

"callService1" 
"b subscribe callService1" 
"a callService2" 

我真的已經預計有"a callService2""b subscribe callService1",我不確定明白這個結果。在b()中我的a.subscribe之前完成callService2.subscribe可以做些什麼?

回答

0

訂閱不按它們在您的代碼中出現的順序運行。當Service1有一些數據時,運行「callService1」和「b subscribe callService1」。 「ServiceService2」將不會運行,直到Service2有一些數據。