File

core/src/rxjs/observe/abstraction/observe-array-base.directive.ts

Description

The base class for *observe directives combining observables using an array of observable values (i.e. [x$, y$]).

Extends

ObserveBaseDirective

Index

Properties
Methods
Outputs

Outputs

completeCalled
Type : EventEmitter<void>
Inherited from ObserveBaseDirective

Triggered when the observable completes. $event will be the void.

errorCalled
Type : EventEmitter<>
Inherited from ObserveBaseDirective

Triggered when an error occurs in the observable's pipeline. $event will be the error.

nextCalled
Type : EventEmitter<TResolved>
Inherited from ObserveBaseDirective

Triggered whenever the observable emits a value. $event will be the emitted value.

Methods

Protected createViewContext
createViewContext(undefined: literal type)
Inherited from ObserveBaseDirective
Parameters:
Name Type Optional
literal type No
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 combineLatest(), contact(), etc.

Parameters:
Name Type Optional Description
input TInput No

The input passed to the directive (which might be an observable, a map or an array of observable for example).

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, next?: (value?: T) => void, error?: (undefined) => void, complete?: () => void)
Inherited from Destroyable
Type parameters:
  • T

Subscribes to an observable and stores the subscription for automatic disposal. When ngOnDestroy() is called, all subscriptions created with this method will unsubscribe.

Parameters:
Name Type Optional Description
observable Observable<T> No

The observable to subscribe to.

next function Yes

(Optional) A callback function to execute on each emission of the observable.

error function Yes

(Optional) A callback function to execute when the observable errors.

complete function Yes

(Optional) A callback function to execute when the observable completes.

Returns: Subscription

The subscription created for the observable.

Properties

Protected Readonly input
Type: BehaviorSubject<TInput | null>
Default value: new BehaviorSubject(null as TInput | null)
Inherited from ObserveBaseDirective

input is set from @Input properties. For some reason, Angular passes-in the first value BEFORE ngOnInit, even though other @Input properties (e.g. showAfter, showFor) are passed AFTER ngOnInit. If subscription occurs in the constructor, input will emit the first observable too fast, which might lead to pipes breaking or misbehaving if they rely on properties to be instantiated first.

This leads to subscribing in ngOnInit, to allow Angular time to initialize those. BUT, if input is a Subject, as the first value was already emitted BEFORE ngOnInit, it will not be captured by our subscription to input. Hence the BehaviorSubject - To allow capturing that first observable.

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 as keyword work.

Protected Readonly destroyed
Type: Subject<void>
Default value: new Subject()
Inherited from Destroyable

Emits a value when ngOnDestroy() is called. Pipe together with takeUntil() to auto unsubscribe from your observables.

observable.pipe(takeUntil(this.destroyed)).subscribe(...);
Protected Readonly subscriptions
Type: Subscription
Default value: new Subscription()
Inherited from Destroyable

A list of all subscriptions manually added using the subscribe() method. These are automatically unsubscribed when ngOnDestroy() is called.

import { Directive  } from '@angular/core';

import { ObserveBaseDirective   } from './observe-base.directive';
import { ResolvedObserveContext } from './types/general';
import { ObservableArray        } from './types/arrays';

/**
 * The base class for `*observe` directives combining observables using an array of observable values (i.e. [x$, y$]).
 *
 * @export
 * @abstract
 * @class ObserveArrayDirective
 * @extends {ObserveBaseDirective<TInput, TResolved, TContext>}
 * @template TInput The type of observable array.
 * @template TResolved The type of resolved array.
 * @template TContext The the of context the directive will provide to the view.
 */
@Directive()
export abstract class ObserveArrayDirective<TInput extends ObservableArray, TResolved, TContext extends ResolvedObserveContext<TResolved> = ResolvedObserveContext<TResolved>>
              extends ObserveBaseDirective<TInput, TResolved, TContext>
{

}

results matching ""

    No results matching ""