core/src/rxjs/on-observer/directives/on-observer-next.directive.ts
Documentation in OnObserverNextDirective.onObserverNext to allow in-template tooltips.
| Selector | [onObserverNext] |
Properties |
|
Methods |
|
Inputs |
Accessors |
| onObserverNext | |
Type : Observable<T>
|
|
|
Renders the template when the specified observable emits a value. FeaturesView ContextUse the microsyntax Delayed renderingSpecify a value for Auto destroySpecify Countdown updatesWhen Remaining is provided by the Multi view modeSpecify View indexIn multi-view mode, the context will contain the index of the view, which can be used for calculations and styling. |
|
| onObserverNextCountdownInterval | |
Type : DurationAnnotation | "animationFrames"
|
|
Only used when passing a value to
|
|
| onObserverNextShowAfter | |
Type : DurationAnnotation
|
|
|
(Optional) The duration for which the directive should wait before rendering the view once an intercepted call is made. You can specify a number, which will be treated as milliseconds, or a string with the format of
Default is TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow. |
|
| onObserverNextShowFor | |
Type : DurationAnnotation
|
|
|
(Optional) The duration for which the view should be rendered. When the duration passes, the view will be auto destroyed. You can specify a number, which will be treated as milliseconds, or a string with the format of
During the time the view is rendered, the context will be updated with a countdown object to facilitate any UI part used to
indicate countdown to the user. The countdown will be exposed through the When unspecified, the view will be destroyed immediately once the observer detects a call different to the intercepted ones. TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow. |
|
| onObserverNextViewMode | |
Type : ViewMode
|
|
|
(Optional) The view mode the directive will operate in:
Default is |
|
| Static ngTemplateContextGuard | |||||||||
ngTemplateContextGuard(directive: OnObserverNextDirective<T>, context)
|
|||||||||
Type parameters:
|
|||||||||
|
Parameters:
Returns:
OnObserverContext<T>
|
|||||||||
| ngOnInit |
ngOnInit()
|
|
Inherited from
OnObserverBaseDirective
|
|
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 renderOnCallsTo |
Type: ObserverName
|
Default value: 'next'
|
|
Inherited from
OnObserverBaseDirective
|
| Protected selector |
Type: string
|
Default value: 'onObserverNext'
|
|
Inherited from
OnObserverBaseDirective
|
| Protected Optional countdownInterval |
Type: DurationAnnotation | "animationFrames"
|
|
Inherited from
OnObserverBaseDirective
|
Only used when passing a value to
|
| Protected Readonly input |
Type: BehaviorSubject<Observable | null>
|
Default value: new BehaviorSubject(null as Observable<T> | null)
|
|
Inherited from
OnObserverBaseDirective
|
Why BehaviorSubject<... | null> and not Subject<...>
This leads to subscribing in ngOnInit, to allow Angular time to initialize those.
BUT, if |
| Protected showAfter |
Type: DurationAnnotation
|
Default value: 0
|
|
Inherited from
OnObserverBaseDirective
|
|
(Optional) The duration for which the directive should wait before rendering the view once an intercepted call is made. You can specify a number, which will be treated as milliseconds, or a string with the format of
Default is TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow. ⚠️ Extending classes should:
|
| Protected Optional showFor |
Type: DurationAnnotation
|
|
Inherited from
OnObserverBaseDirective
|
|
(Optional) The duration for which the view should be rendered. When the duration passes, the view will be auto destroyed. You can specify a number, which will be treated as milliseconds, or a string with the format of
During the time the view is rendered, the context will be updated with a countdown object to facilitate any UI part used to
indicate countdown to the user. The countdown will be exposed through the When unspecified, the view will be destroyed immediately once the observer detects a call different to the intercepted ones. TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow. ⚠️ Extending classes should:
|
| Protected viewMode |
Type: ViewMode
|
Default value: 'single'
|
|
Inherited from
OnObserverBaseDirective
|
|
(Optional) The view mode the directive will operate in:
Default is ⚠️ Extending classes should:
|
| 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 |
| onObserverNext | ||||||
setonObserverNext(value: Observable
|
||||||
|
Renders the template when the specified observable emits a value. FeaturesView ContextUse the microsyntax Delayed renderingSpecify a value for Auto destroySpecify Countdown updatesWhen Remaining is provided by the Multi view modeSpecify View indexIn multi-view mode, the context will contain the index of the view, which can be used for calculations and styling.
Parameters :
Returns:
void
|
||||||
| onObserverNextViewMode | ||||||
setonObserverNextViewMode(viewMode: ViewMode)
|
||||||
|
(Optional) The view mode the directive will operate in:
Default is
Parameters :
Returns:
void
|
||||||
| onObserverNextShowAfter | ||||||
setonObserverNextShowAfter(duration: DurationAnnotation)
|
||||||
|
(Optional) The duration for which the directive should wait before rendering the view once an intercepted call is made. You can specify a number, which will be treated as milliseconds, or a string with the format of
Default is TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow.
Parameters :
Returns:
void
|
||||||
| onObserverNextShowFor | ||||||
setonObserverNextShowFor(duration: DurationAnnotation)
|
||||||
|
(Optional) The duration for which the view should be rendered. When the duration passes, the view will be auto destroyed. You can specify a number, which will be treated as milliseconds, or a string with the format of
During the time the view is rendered, the context will be updated with a countdown object to facilitate any UI part used to
indicate countdown to the user. The countdown will be exposed through the When unspecified, the view will be destroyed immediately once the observer detects a call different to the intercepted ones. TODO: ADD LINK TO TOUR OR FULL WIKI PAGE Read more About render flow.
Parameters :
Returns:
void
|
||||||
| onObserverNextCountdownInterval | ||||||
setonObserverNextCountdownInterval(duration: DurationAnnotation | "animationFrames")
|
||||||
Only used when passing a value to
|
| Name | Type | Optional |
| duration |
DurationAnnotation | "animationFrames"
|
No |
void
import { Observable } from 'rxjs';
import { Directive, Input } from '@angular/core';
import { DurationAnnotation, ObserverName, ViewMode } from '../abstraction/types/general';
import { OnObserverContext } from '../abstraction/types/on-observer-context';
import { OnObserverBaseDirective } from '../abstraction/on-observer-base.directive';
/**
* Documentation in {@link OnObserverNextDirective.onObserverNext} to allow in-template tooltips.
*
* @export
* @class OnObserverNextDirective
* @extends {OnObserverBaseDirective<T>}
* @template T The type of value the observable emits.
*/
@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: '[onObserverNext]'
})
export class OnObserverNextDirective<T> extends OnObserverBaseDirective<T>
{
protected selector = 'onObserverNext';
protected renderOnCallsTo: ObserverName = 'next';
/**
* Renders the template when the specified observable emits a value.
*
* ## Features
*
* #### View Context
* Use the microsyntax `as` keyword to assign resolved values to a variable.
* Use the microsyntax `let` keyword to assign the {@link OnObserverContext full context object} to a variable (e.g. `let context`).
*
* #### Delayed rendering
* Specify a value for {@link OnObserverBaseDirective.showAfter `showAfter`} to delay rendering.
*
* #### Auto destroy
* Specify {@link OnObserverBaseDirective.showFor `showFor`} to automatically destroy the view after a certain duration.
*
* #### Countdown updates
* When {@link OnObserverBaseDirective.showFor `showFor`} is specified, the view context will be updated with the time remaining until the view
* is destroyed and the time elapsed since it was rendered. This allows giving the user feedback in a progress bar, a spinner, a textual timer
* or any other UI component.
*
* Remaining is provided by the {@link OnObserverContext.remaining `remaining`} property. Elapsed time is provided by the {@link OnObserverContext.elapsed `elapsed`}
* property. Access it by assigning a variable using `let`, like so:
* `let remaining = remaining`
*
* #### Multi view mode
* Specify {@link OnObserverBaseDirective.viewMode `viewMode = 'multiple'`} to enable rendering a new view for each intercepted call
* instead of updating a single rendered view. This allows stacking logs, notification snackbars, or any other aggregation functionality.
* Combined with {@link OnObserverBaseDirective.showFor `showFor`}, this is great for disappearing messages/notifications.
*
* #### View index
* In multi-view mode, the context will contain the index of the view, which can be used for calculations and styling.
*/
@Input() public set onObserverNext(value: Observable<T>) { this.input.next(value); }
/**
* (Optional) The view mode the directive will operate in:
* `'single'` - A single view will be rendered on intercepted calls. If a view has already been rendered when a call is intercepted,
* the existing view will be updated with data from the new call.
*
* `'multiple'` - Every new intercepted call will render a new view with its own context and data encapsulated from the current call.
*
* Default is `'single'`.
*/
@Input() public set onObserverNextViewMode (viewMode: ViewMode ) { this.viewMode = viewMode; }
/**
* (Optional) The duration for which the directive should wait before rendering the view once an intercepted call is made.
*
* You can specify a number, which will be treated as milliseconds, or a string with the format of `<number><ms | s | ms>`.
* Numbers can be either integers or floats.
* For example:
* - `3000` - Wait for 3 seconds, then render the view.
* - `'10s'` - Wait for 10 seconds, then render the view.
* - `'0.5m'` - Wait for 30 seconds, then render the view.
* - `'100ms'` - Wait for 100 milliseconds, then render the view.
*
* Default is `0`, meaning immediately render the view.
*
* TODO: ADD LINK TO TOUR OR FULL WIKI PAGE
* Read more {@link OnObserverBaseDirective About render flow}.
**/
@Input() public set onObserverNextShowAfter (duration: DurationAnnotation) { this.showAfter = duration; }
/**
* (Optional) The duration for which the view should be rendered. When the duration passes, the view will be auto destroyed.
*
* You can specify a number, which will be treated as milliseconds, or a string with the format of `<number><ms | s | ms>`.
* Numbers can be either integers or floats.
* For example:
* - `3000` - The view will be destroyed after 3 seconds.
* - `'10s'` - The view will be destroyed after 10 seconds.
* - `'0.5m'` - The view will be destroyed after 30 seconds.
* - `'100ms'` - The view will be destroyed after 100 milliseconds.
*
* During the time the view is rendered, the context will be updated with a countdown object to facilitate any UI part used to
* indicate countdown to the user. The countdown will be exposed through the {@link OnObserverContext.remaining `remaining`}
* property and the elapsed time through {@link OnObserverContext.elapsed `elapsed`} property in the view context and can both
* be accessed be declaring a `let` variable (e.g. `let remaining = remaining`).
* See {@link OnObserverBaseDirective.countdownInterval `countdownInterval`} for changing the updates interval.
*
* When unspecified, the view will be destroyed immediately once the observer detects a call different to the intercepted ones.
*
* TODO: ADD LINK TO TOUR OR FULL WIKI PAGE
* Read more {@link OnObserverBaseDirective About render flow}.
**/
@Input() public set onObserverNextShowFor (duration: DurationAnnotation) { this.showFor = duration; };
/**
* ### Only used when passing a value to {@link OnObserverBaseDirective.showFor `showFor`}.
*
* (Optional) The interval with which countdown updates should be made to the view's context before it auto destroys.
* The lower the value, the more updates will be made to the context, but the more resources your directive will consume.
*
* You can specify a number, which will be treated as milliseconds, or a string with the format of `<number><ms | s | ms>`.
* Numbers can be either integers or floats.
* For example:
* - `3000` - 3 seconds between each update.
* - `'10s'` - 10 seconds between each update.
* - `'0.5m'` - 30 seconds between each update.
* - `'100ms'` - 100 milliseconds between each update.
*
* You can also specify `'animationFrames'` so the countdown gets updated each time the browser is working on animations.
*
* When unspecified, the total duration of the countdown will be divided by {@link DefaultCountdownUpdateCount `DefaultCountdownUpdateCount`}
* to get a fixed interval which will make for {@link DefaultCountdownUpdateCount `DefaultCountdownUpdateCount`} countdown updates.
*/
@Input() public set onObserverNextCountdownInterval(duration: DurationAnnotation | 'animationFrames') { this.countdownInterval = duration; };
static ngTemplateContextGuard<T>(directive: OnObserverNextDirective<T>, context: unknown): context is OnObserverContext<T> { return true; }
}