Advertisement
Guest User

Untitled

a guest
May 26th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. @Directive({
  2. selector: '[asyncControl]'
  3. })
  4. export class AsyncControlDirective implements AfterViewInit, OnDestroy {
  5. destroyed$: Subject<boolean> = new Subject();
  6.  
  7. constructor(private changeDetector: ChangeDetectorRef, private formControl: NgControl) {
  8. }
  9.  
  10. public ngAfterViewInit(): void {
  11. this.formControl.statusChanges
  12. .pipe(
  13. takeUntil(this.destroyed$)
  14. )
  15. .subscribe(
  16. _ => this.changeDetector.markForCheck()
  17. );
  18. }
  19.  
  20. ngOnDestroy() {
  21. this.destroyed$.next(true);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement