Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 6x 6x 6x 6x 3x 3x 3x 3x | import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { ReplaySubject, asyncScheduler, scheduled, switchMap } from 'rxjs';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
/**
* Displays basket-related HTTP error messages and automatically scrolls
* the message into view whenever the error input changes.
*/
@Component({
selector: 'ish-basket-error-message',
templateUrl: './basket-error-message.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BasketErrorMessageComponent implements OnChanges {
@Input({ required: true }) error: HttpError;
@Input() cssClass = 'alert alert-danger';
// default values to control scrolling behavior
scrollSpacing = 64;
private scrollTrigger$ = new ReplaySubject<void>(1);
// Emits false, then true asynchronously to ensure the directive's ngOnChanges is triggered
scrollToMessage$ = this.scrollTrigger$.pipe(switchMap(() => scheduled([false, true], asyncScheduler)));
ngOnChanges() {
Iif (this.error) {
this.scrollTrigger$.next();
}
}
}
|