of
function stable
Converts the arguments to an observable sequence.
of<T>(...args: (SchedulerLike | T)[]): Observable<T>
Parameters
| args | Type: |
Returns
Observable<T>: An Observable that emits the arguments described above and then completes.
Description
Each argument becomes a next notification.
Unlike from, it does not do any flattening and emits each argument in whole as a separate next notification.
Examples
Emit the values 10, 20, 30
import { of } from 'rxjs';
of(10, 20, 30)
.subscribe(
next => console.log('next:', next),
err => console.log('error:', err),
() => console.log('the end'),
);
// Outputs
// next: 10
// next: 20
// next: 30
// the end Emit the array [1, 2, 3]
import { of } from 'rxjs';
of([1, 2, 3])
.subscribe(
next => console.log('next:', next),
err => console.log('error:', err),
() => console.log('the end'),
);
// Outputs
// next: [1, 2, 3]
// the end Overloads
of(value: null): Observable<null>
Parameters
| value | Type: |
Returns
Observable<null>
of(value: undefined): Observable<undefined>
Parameters
| value | Type: |
Returns
Observable<undefined>
of(scheduler: SchedulerLike): Observable<never>
Deprecation Notes
The scheduler parameter will be removed in v8. Use scheduled. Details: https://rxjs.dev/deprecations/scheduler-argument
Parameters
| scheduler | Type: |
Returns
Observable<never>
of(...valuesAndScheduler: [any, SchedulerLike]): Observable<ValueFromArray<A>>
Deprecation Notes
The scheduler parameter will be removed in v8. Use scheduled. Details: https://rxjs.dev/deprecations/scheduler-argument
Parameters
| valuesAndScheduler | Type: |
Returns
Observable<ValueFromArray<A>>
of(): Observable<never>
Parameters
There are no parameters.
Returns
Observable<never>
of(): Observable<T>
Deprecation Notes
Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8.
Parameters
There are no parameters.
Returns
Observable<T>
of(value: T): Observable<T>
Parameters
| value | Type: |
Returns
Observable<T>
of(...values: A): Observable<ValueFromArray<A>>
Parameters
| values | Type: |
Returns
Observable<ValueFromArray<A>>
See Also
© 2015–2021 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/index/function/of