Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import { Directive, forwardRef } from '@angular/core';
  2. import {Validators, FormControl} from "@angular/forms";
  3. import { NG_VALUE_ACCESSOR, ControlValueAccessor, NG_VALIDATORS } from "@angular/forms";
  4.  
  5. @Directive( {
  6. selector: "input[type=file]",
  7. host: {
  8. "(change)": "onChange($event.target.files)",
  9. "(blur)": "onTouched()"
  10. },
  11. providers: [
  12. { provide: NG_VALIDATORS, useExisting: forwardRef( () => FileValidatorDirective ), multi: true },
  13. { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef( () => FileValidatorDirective ), multi: true }
  14. ]
  15. } )
  16.  
  17. export class FileValidatorDirective implements ControlValueAccessor, Validators {
  18. onChange = () => {
  19.  
  20. };
  21.  
  22. onTouched = () => {
  23. };
  24.  
  25. writeValue( value ) {
  26. debugger;
  27. }
  28.  
  29. registerOnChange( fn: any ) {
  30. debugger;
  31. this.onChange = fn;
  32. }
  33.  
  34. registerOnTouched( fn: any ) {
  35. this.onTouched = fn;
  36. }
  37.  
  38. validate( c: FormControl ): {[key: string]: any} {
  39. debugger;
  40. return c.value == null || c.value.length == 0 ? { "required": true } : null;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement