title: Angular Custom validator: why export function?
body: <p>I'm doing my first steps in Angular and had to make a custom maximum validator for a number field in a template form. This is it:</p>
  
  <pre class="lang-js prettyprint-override"><code>import {Directive, Input} from '@angular/core';
  import {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn} from '@angular/forms';
  
  @Directive({
    selector: '[appMaximumValue]',
    providers: [{provide: NG_VALIDATORS, useExisting: MaximumValueDirective, multi: true}]
  })
  export class MaximumValueDirective implements Validator {
    @Input('appMaximumValue') maximumValue: number;
  
    constructor() {
    }
  
    validate(control: AbstractControl): ValidationErrors | null {
      return this.maximumValue ? maximumValueValidator(this.maximumValue)(control) : null;
    }
  }
  
  export function maximumValueValidator(minimum: number): ValidatorFn {
    return (control: AbstractControl): { [key: string]: any } | null =&gt; {
      return control.value &gt; minimum ? {'maximumValue': {value: control.value}} : null;
    };
  }
  </code></pre>
  
  <p>After thinking about it I discovered that it also works without the export function:</p>
  
  <pre class="lang-js prettyprint-override"><code>import {Directive, Input} from '@angular/core';
  import {AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn} from '@angular/forms';
  
  @Directive({
    selector: '[appMaximumValue]',
    providers: [{provide: NG_VALIDATORS, useExisting: MaximumValueDirective, multi: true}]
  })
  export class MaximumValueDirective implements Validator {
    @Input('appMaximumValue') maximumValue: number;
  
    constructor() {
    }
  
    validate(control: AbstractControl): ValidationErrors | null {
      return Number(control.value) &gt; this.maximumValue ? {'maximumValue': {value: control.value}} : null;
    }
  }
  </code></pre>
  
  <p>So my question is, what is the reason for this export function?</p>