W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
返回一個 Observable,它將在源流完成時最多計數(shù)一次重新訂閱源流。
repeat<T>(count: number = -1): MonoTypeOperatorFunction
<T>
計數(shù) | 可選的。默認值為-1 。重復源可觀察項的次數(shù),計數(shù)為 0 將產(chǎn)生一個空的可觀察項。 |
---|
MonoTypeOperatorFunction<T>
:一個 Observable,它將在源流完成時最多計數(shù)一次重新訂閱源流。
重復源上發(fā)出的所有值。就像 retry
,但是用于非錯誤情況。
與相似 retry
,此運算符在無錯誤的情況下重復由源發(fā)出的項目流。重復對于創(chuàng)建具有某些重復模式或節(jié)奏的可觀察對象很有用。
注意:repeat(0)
返回一個可觀察的空值,repeat()
并將永遠重復
重復消息流
import { of } from 'rxjs';
import { repeat, delay } from 'rxjs/operators';
const source = of('Repeat message');
const example = source.pipe(repeat(3));
example.subscribe(x => console.log(x));
// Results
// Repeat message
// Repeat message
// Repeat message
重復3個值,兩次
import { interval } from 'rxjs';
import { repeat, take } from 'rxjs/operators';
const source = interval(1000);
const example = source.pipe(take(3), repeat(2));
example.subscribe(x => console.log(x));
// Results every second
// 0
// 1
// 2
// 0
// 1
// 2
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: