Class: Subject<T>
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:11
A Subject is a special type of Observable that allows values to be multicasted to many Observers. Subjects are like EventEmitters.
Every Subject is an Observable and an Observer. You can subscribe to a Subject, and you can call next to feed values as well as error and complete.
Extends
Observable<T>
Extended by
Type Parameters
T
T
Implements
SubscriptionLike
Constructors
Constructor
new Subject<
T>():Subject<T>
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:28
Returns
Subject<T>
Overrides
Observable<T>.constructor
Properties
closed
closed:
boolean
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:12
Implementation of
SubscriptionLike.closed
hasError
hasError:
boolean
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:19
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
isStopped
isStopped:
boolean
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:17
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
observers
observers:
Observer<T>[]
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:15
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
operator
operator:
Operator<any,T> |undefined
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:17
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
Inherited from
Observable.operator
source
source:
Observable<any> |undefined
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:13
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
Inherited from
Observable.source
thrownError
thrownError:
any
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:21
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
create()
staticcreate: (...args) =>any
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:27
Creates a "subject" by basically gluing an observer to an observable.
Parameters
args
...any[]
Returns
any
Deprecated
Recommended you do not use. Will be removed at some point in the future. Plans for replacement still under discussion.
Overrides
Observable.create
Accessors
observed
Get Signature
get observed():
boolean
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:35
Returns
boolean
Methods
asObservable()
asObservable():
Observable<T>
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:42
Creates a new Observable with this Subject as the source. You can do this to create custom Observer-side logic of the Subject and conceal it from code that uses the Observable.
Returns
Observable<T>
Observable that this Subject casts to.
complete()
complete():
void
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:33
Returns
void
error()
error(
err):void
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:32
Parameters
err
any
Returns
void
forEach()
Call Signature
forEach(
next):Promise<void>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:90
Used as a NON-CANCELLABLE means of subscribing to an observable, for use with APIs that expect promises, like async/await. You cannot unsubscribe from this.
WARNING: Only use this with observables you know will complete. If the source observable does not complete, you will end up with a promise that is hung up, and potentially all of the state of an async function hanging out in memory. To avoid this situation, look into adding something like timeout, take, takeWhile, or takeUntil amongst others.
Example
import { interval, take } from 'rxjs';
const source$ = interval(1000).pipe(take(4));
async function getTotal() {
let total = 0;
await source$.forEach(value => {
total += value;
console.log('observable -> ' + value);
});
return total;
}
getTotal().then(
total => console.log('Total: ' + total)
);
// Expected:
// 'observable -> 0'
// 'observable -> 1'
// 'observable -> 2'
// 'observable -> 3'
// 'Total: 6'Parameters
next
(value) => void
A handler for each value emitted by the observable.
Returns
Promise<void>
A promise that either resolves on observable completion or rejects with the handled error.
Inherited from
Observable.forEach
Call Signature
forEach(
next,promiseCtor):Promise<void>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:102
Parameters
next
(value) => void
a handler for each value emitted by the observable
promiseCtor
PromiseConstructorLike
a constructor function used to instantiate the Promise
Returns
Promise<void>
a promise that either resolves on observable completion or rejects with the handled error
Deprecated
Passing a Promise constructor will no longer be available in upcoming versions of RxJS. This is because it adds weight to the library, for very little benefit. If you need this functionality, it is recommended that you either polyfill Promise, or you create an adapter to convert the returned native promise to whatever promise implementation you wanted. Will be removed in v8.
Inherited from
Observable.forEach
lift()
lift<
R>(operator):Observable<R>
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:30
Type Parameters
R
R
Parameters
operator
Operator<T, R>
Returns
Observable<R>
Deprecated
Internal implementation detail, do not use directly. Will be made internal in v8.
Overrides
Observable.lift
next()
next(
value):void
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:31
Parameters
value
T
Returns
void
pipe()
Call Signature
pipe():
Observable<T>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:103
Returns
Observable<T>
Inherited from
Observable.pipe
Call Signature
pipe<
A>(op1):Observable<A>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:104
Type Parameters
A
A
Parameters
op1
OperatorFunction<T, A>
Returns
Observable<A>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B>(op1,op2):Observable<B>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:105
Type Parameters
A
A
B
B
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
Returns
Observable<B>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C>(op1,op2,op3):Observable<C>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:106
Type Parameters
A
A
B
B
C
C
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
Returns
Observable<C>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D>(op1,op2,op3,op4):Observable<D>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:107
Type Parameters
A
A
B
B
C
C
D
D
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
Returns
Observable<D>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E>(op1,op2,op3,op4,op5):Observable<E>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:108
Type Parameters
A
A
B
B
C
C
D
D
E
E
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
Returns
Observable<E>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E,F>(op1,op2,op3,op4,op5,op6):Observable<F>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:109
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
op6
OperatorFunction<E, F>
Returns
Observable<F>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E,F,G>(op1,op2,op3,op4,op5,op6,op7):Observable<G>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:110
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
op6
OperatorFunction<E, F>
op7
OperatorFunction<F, G>
Returns
Observable<G>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E,F,G,H>(op1,op2,op3,op4,op5,op6,op7,op8):Observable<H>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:111
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
op6
OperatorFunction<E, F>
op7
OperatorFunction<F, G>
op8
OperatorFunction<G, H>
Returns
Observable<H>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E,F,G,H,I>(op1,op2,op3,op4,op5,op6,op7,op8,op9):Observable<I>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:112
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
op6
OperatorFunction<E, F>
op7
OperatorFunction<F, G>
op8
OperatorFunction<G, H>
op9
OperatorFunction<H, I>
Returns
Observable<I>
Inherited from
Observable.pipe
Call Signature
pipe<
A,B,C,D,E,F,G,H,I>(op1,op2,op3,op4,op5,op6,op7,op8,op9, ...operations):Observable<unknown>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:113
Type Parameters
A
A
B
B
C
C
D
D
E
E
F
F
G
G
H
H
I
I
Parameters
op1
OperatorFunction<T, A>
op2
OperatorFunction<A, B>
op3
OperatorFunction<B, C>
op4
OperatorFunction<C, D>
op5
OperatorFunction<D, E>
op6
OperatorFunction<E, F>
op7
OperatorFunction<F, G>
op8
OperatorFunction<G, H>
op9
OperatorFunction<H, I>
operations
...OperatorFunction<any, any>[]
Returns
Observable<unknown>
Inherited from
Observable.pipe
subscribe()
Call Signature
subscribe(
observerOrNext?):Subscription
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:43
Parameters
observerOrNext?
Partial<Observer<T>> | (value) => void
Returns
Inherited from
Observable.subscribe
Call Signature
subscribe(
next?,error?,complete?):Subscription
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:45
Parameters
next?
(value) => void | null
error?
(error) => void | null
complete?
() => void | null
Returns
Deprecated
Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments
Inherited from
Observable.subscribe
toPromise()
Call Signature
toPromise():
Promise<T|undefined>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:115
Returns
Promise<T | undefined>
Deprecated
Replaced with firstValueFrom and lastValueFrom. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise
Inherited from
Observable.toPromise
Call Signature
toPromise(
PromiseCtor):Promise<T|undefined>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:117
Parameters
PromiseCtor
PromiseConstructor
Returns
Promise<T | undefined>
Deprecated
Replaced with firstValueFrom and lastValueFrom. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise
Inherited from
Observable.toPromise
Call Signature
toPromise(
PromiseCtor):Promise<T|undefined>
Defined in: node_modules/rxjs/dist/types/internal/Observable.d.ts:119
Parameters
PromiseCtor
PromiseConstructorLike
Returns
Promise<T | undefined>
Deprecated
Replaced with firstValueFrom and lastValueFrom. Will be removed in v8. Details: https://rxjs.dev/deprecations/to-promise
Inherited from
Observable.toPromise
unsubscribe()
unsubscribe():
void
Defined in: node_modules/rxjs/dist/types/internal/Subject.d.ts:34
Returns
void
Implementation of
SubscriptionLike.unsubscribe