Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Directive, forwardRef } from '@angular/core';
- import {Validators, FormControl} from "@angular/forms";
- import { NG_VALUE_ACCESSOR, ControlValueAccessor, NG_VALIDATORS } from "@angular/forms";
- @Directive( {
- selector: "input[type=file]",
- host: {
- "(change)": "onChange($event.target.files)",
- "(blur)": "onTouched()"
- },
- providers: [
- { provide: NG_VALIDATORS, useExisting: forwardRef( () => FileValidatorDirective ), multi: true },
- { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef( () => FileValidatorDirective ), multi: true }
- ]
- } )
- export class FileValidatorDirective implements ControlValueAccessor, Validators {
- onChange = () => {
- };
- onTouched = () => {
- };
- writeValue( value ) {
- debugger;
- }
- registerOnChange( fn: any ) {
- debugger;
- this.onChange = fn;
- }
- registerOnTouched( fn: any ) {
- this.onTouched = fn;
- }
- validate( c: FormControl ): {[key: string]: any} {
- debugger;
- return c.value == null || c.value.length == 0 ? { "required": true } : null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement