core/src/rxjs/observe/abstraction/observe-base.directive.ts
The base class for all *observeXXX
directives.
This directive bind an observable or a collection of observables with a template, causing the values in the template to be updated whenever the observables emit.
Any template assigned with the directive will render immediately, and its view context will be updated with the emitted value on each emission. The directive will be responsible for subscribing on init and unsubscribing on destroy.
The watched observable will automatically be multicasted so that any child observables created by the template will use the same stream.
The shared observable can be accessed using the let source = source
microsyntax.
Whenever the observable changes state or emits a value, the corresponding event is emitted:
nextCalled
- A value has been emitted. $event
will be the emitted value.
errorCalled
- An error has occured in the pipeline. $event
will be the error.
completeCalled
- The observable has completed. $event
will be void.
Because of limitations to Angular's Structural Directives, in order to bind the events the desugared syntax must be used. This, for example, will trigger the event:
This will NOT trigger the event:
As the base class cannot deduce the directive selector (e.g. observeLatest
, observeMerge
, etc.) the extending class
is required to do 4 things:
selector
member and assign it with the directive's selector.@Input() public set <selector>(value: T)
which will pass its value to the input
member.These will enable Angular features like template type checking and the microsyntax as
keyword.
Properties |
|
Methods |
|
Outputs |
constructor(template: TemplateRef
|
|||||||||
Parameters:
|
|||||||||
completeCalled | |
Type : EventEmitter<void>
|
|
Triggered when the observable completes. |
errorCalled | |
Type : EventEmitter<>
|
|
Triggered when an error occurs in the observable's pipeline. |
nextCalled | |
Type : EventEmitter<TResolved>
|
|
Triggered whenever the observable emits a value. |
Protected createViewContext | |||||
createViewContext(undefined: literal type)
|
|||||
Parameters:
Returns:
TContext
|
|||||
ngOnInit |
ngOnInit()
|
Returns:
void
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
Destroyable
|
Returns:
void
|
Protected subscribe | ||||||||||||||||||||
subscribe(observable: Observable
|
||||||||||||||||||||
Inherited from
Destroyable
|
||||||||||||||||||||
Type parameters:
|
||||||||||||||||||||
Subscribes to an observable and stores the subscription for automatic disposal.
When
Parameters:
Returns:
Subscription
The subscription created for the observable. |
||||||||||||||||||||
Protected Readonly input |
Type: BehaviorSubject<TInput | null>
|
Default value: new BehaviorSubject(null as TInput | null)
|
Why BehaviorSubject<s | null> and not Subject<TInput>
This leads to subscribing in ngOnInit, to allow Angular time to initialize those.
BUT, if |
Protected Abstract Readonly selector |
Type: string
|
The selector defined for the directive extending this class. Will be used to create a corresponding
property in the view context in order to make the micro-syntax |
Protected Readonly destroyed |
Type: Subject<void>
|
Default value: new Subject()
|
Inherited from
Destroyable
|
Emits a value when |
Protected Readonly subscriptions |
Type: Subscription
|
Default value: new Subscription()
|
Inherited from
Destroyable
|
A list of all subscriptions manually added using the |