publishBehaviour使用AsyncSubject,并返回ConnectableObservable。connect()方法必须用于订阅创建的可观察对象。
例
import { interval } from 'rxjs'; import { take, publishLast} from 'rxjs/operators'; let observer = interval(1000).pipe( take(10), publishLast() ); const subscribe_one = observer.subscribe( x => console.log("Value from Sub1 = "+x) ); const subscribe_two = observer.subscribe( x => console.log("Value from Sub2 = "+x) ); observer.connect();
输出
作者:terry,如若转载,请注明出处:https://www.web176.com/rxjs/1941.html