function stable operator
Returns an observable that, at the moment of subscription, will synchronously emit all values provided to this operator, then subscribe to the source and mirror all of its emissions to subscribers.
startWith<T, D>(...values: D[]): OperatorFunction<T, T | D> values | D[] | Items you want the modified Observable to emit first. |
OperatorFunction<T, T | D>: A function that returns an Observable that synchronously emits provided values before subscribing to the source Observable.
This is a useful way to know when subscription has occurred on an existing observable.
First emits its arguments in order, and then any emissions from the source.
Emit a value when a timer starts.
import { timer, map, startWith } from 'rxjs';
timer(1000)
.pipe(
map(() => 'timer emit'),
startWith('timer start')
)
.subscribe(x => console.log(x));
// results:
// 'timer start'
// 'timer emit' startWith(value: null): OperatorFunction<T, T | null> value | null |
OperatorFunction<T, T | null>
startWith(value: undefined): OperatorFunction<T, T | undefined> value | undefined |
OperatorFunction<T, T | undefined>
startWith(...valuesAndScheduler: [...A, SchedulerLike]): OperatorFunction<T, T | ValueFromArray<A>> valuesAndScheduler | [...A, SchedulerLike] |
OperatorFunction<T, T | ValueFromArray<A>>
startWith(...values: A): OperatorFunction<T, T | ValueFromArray<A>> values | A |
OperatorFunction<T, T | ValueFromArray<A>>
© 2015–2022 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/operators/startWith