core/src/rxjs/observe/abstraction/observe-map-base.directive.ts
The base class for *observe directives combining observables using a map of observable values (i.e. { x: x$, y: y$ }).
Emitted values will be available as the implicit context values but will also be spread into the context by key. Meaning, this would work:
<div *observeXXX="{ x: x$, y: y$ } as result">{{result.x}}</div>And this also:
<div *observeXXX="{ x: x$, y: y$ }; let x = x">{{x}}</div>
Properties |
|
Methods |
|
Outputs |
| completeCalled | |
Type : EventEmitter<void>
|
|
|
Inherited from
ObserveBaseDirective
|
|
|
Defined in
ObserveBaseDirective:81
|
|
|
Triggered when the observable completes. |
|
| errorCalled | |
Type : EventEmitter<>
|
|
|
Inherited from
ObserveBaseDirective
|
|
|
Defined in
ObserveBaseDirective:75
|
|
|
Triggered when an error occurs in the observable's pipeline. |
|
| nextCalled | |
Type : EventEmitter<TResolved>
|
|
|
Inherited from
ObserveBaseDirective
|
|
|
Defined in
ObserveBaseDirective:69
|
|
|
Triggered whenever the observable emits a value. |
|
| Protected createViewContext | ||||||
createViewContext(data: literal type)
|
||||||
|
Inherited from
ObserveBaseDirective
|
||||||
|
Parameters:
Returns:
TContext
|
||||||
| ngOnInit |
ngOnInit()
|
|
Inherited from
ObserveBaseDirective
|
|
Returns:
void
|
| Protected Abstract observeInput | ||||||||
observeInput(input: TInput)
|
||||||||
|
Inherited from
ObserveBaseDirective
|
||||||||
|
Takes the input passed to the directive (which might be an observable, a map or an array of observable for example) and creates an observable that combines and represents all the observables in the value. Intended for applying functions like
Parameters:
Returns:
Observable<TResolved>
An observable which combines and represents all the observables in the input value. |
||||||||
| 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)
|
|
Inherited from
ObserveBaseDirective
|
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
|
|
Inherited from
ObserveBaseDirective
|
|
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 |
import { Directive } from '@angular/core';
import { Observable } from 'rxjs';
import { ObserveBaseDirective } from './observe-base.directive';
import { ObservableMap, EmittedMapOf, ObserveMapContext } from './types/maps';
/**
* The base class for `*observe` directives combining observables using a map of observable values (i.e. { x: x$, y: y$ }).
*
* Emitted values will be available as the implicit context values but will also be spread into the context by key.
* Meaning, this would work:
* ```html
* <div *observeXXX="{ x: x$, y: y$ } as result">{{result.x}}</div>
* ```
*
* And this also:
* ```
* <div *observeXXX="{ x: x$, y: y$ }; let x = x">{{x}}</div>
* ```
*
* @export
* @abstract
* @class ObserveMapDirective
* @extends {ObserveBaseDirective<TInput, EmittedMapOf<TInput>, TContext>}
* @template TInput The type of observable map.
* @template TContext The the of context the directive will provide to the view.
*/
@Directive()
export abstract class ObserveMapDirective<TInput extends ObservableMap, TContext extends ObserveMapContext<TInput>>
extends ObserveBaseDirective<TInput, EmittedMapOf<TInput>, TContext>
{
protected override createViewContext(data: { value?: EmittedMapOf<TInput> | null , source?: Observable<EmittedMapOf<TInput>> }): TContext
{
// Spread the values emitted from the observable to allow `let` microsyntax and directly accessing them
return { ...super.createViewContext(data), ...data.value };
}
}