This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {DOCUMENT} from '@angular/common'; | |
| import {inject, InjectionToken} from '@angular/core'; | |
| export const WINDOW = new InjectionToken<Window>( | |
| 'An abstraction over global window object', | |
| { | |
| factory: () => { | |
| const {defaultView} = inject(DOCUMENT); | |
| if (!defaultView) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {AbstractControl, FormArray, FormGroup} from '@angular/forms'; | |
| export function markControlAsTouchedAndValidate(control: AbstractControl) { | |
| if (control instanceof FormArray) { | |
| control.controls.forEach(nestedControl => { | |
| markControlAsTouchedAndValidate(nestedControl); | |
| }); | |
| return; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class ReplayControlValueChanges<T> extends Observable<T> { | |
| constructor(control: AbstractControl | AbstractControlDirective) { | |
| super(subscriber => { | |
| if (!control.valueChanges) { | |
| throw new Error('Control does not have valueChanges'); | |
| } | |
| control.valueChanges.pipe(startWith(control.value)).subscribe(subscriber); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function watch<T>( | |
| changeDetectorRef: ChangeDetectorRef, | |
| ): MonoTypeOperatorFunction<T> { | |
| return (source: Observable<T>) => | |
| source.pipe( | |
| tap(() => { | |
| changeDetectorRef.markForCheck(); | |
| }), | |
| ); | |
| } |
NewerOlder