"Fossies" - the Fresh Open Source Software Archive

Member "angular-8.2.14/packages/forms/src/directives/abstract_form_group_directive.ts" (13 Nov 2019, 2705 Bytes) of package /linux/www/angular-8.2.14.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * @license
    3  * Copyright Google Inc. All Rights Reserved.
    4  *
    5  * Use of this source code is governed by an MIT-style license that can be
    6  * found in the LICENSE file at https://angular.io/license
    7  */
    8 
    9 import {OnDestroy, OnInit} from '@angular/core';
   10 
   11 import {FormGroup} from '../model';
   12 
   13 import {ControlContainer} from './control_container';
   14 import {Form} from './form_interface';
   15 import {composeAsyncValidators, composeValidators, controlPath} from './shared';
   16 import {AsyncValidatorFn, ValidatorFn} from './validators';
   17 
   18 
   19 
   20 /**
   21  * @description
   22  * A base class for code shared between the `NgModelGroup` and `FormGroupName` directives.
   23  *
   24  * @publicApi
   25  */
   26 export class AbstractFormGroupDirective extends ControlContainer implements OnInit, OnDestroy {
   27   /**
   28    * @description
   29    * The parent control for the group
   30    *
   31    * @internal
   32    */
   33   // TODO(issue/24571): remove '!'.
   34   _parent !: ControlContainer;
   35 
   36   /**
   37    * @description
   38    * An array of synchronous validators for the group
   39    *
   40    * @internal
   41    */
   42   // TODO(issue/24571): remove '!'.
   43   _validators !: any[];
   44 
   45   /**
   46    * @description
   47    * An array of async validators for the group
   48    *
   49    * @internal
   50    */
   51   // TODO(issue/24571): remove '!'.
   52   _asyncValidators !: any[];
   53 
   54   /**
   55    * @description
   56    * An internal callback method triggered on the instance after the inputs are set.
   57    * Registers the group with its parent group.
   58    */
   59   ngOnInit(): void {
   60     this._checkParentType();
   61     this.formDirective !.addFormGroup(this);
   62   }
   63 
   64   /**
   65    * @description
   66    * An internal callback method triggered before the instance is destroyed.
   67    * Removes the group from its parent group.
   68    */
   69   ngOnDestroy(): void {
   70     if (this.formDirective) {
   71       this.formDirective.removeFormGroup(this);
   72     }
   73   }
   74 
   75   /**
   76    * @description
   77    * The `FormGroup` bound to this directive.
   78    */
   79   get control(): FormGroup { return this.formDirective !.getFormGroup(this); }
   80 
   81   /**
   82    * @description
   83    * The path to this group from the top-level directive.
   84    */
   85   get path(): string[] { return controlPath(this.name, this._parent); }
   86 
   87   /**
   88    * @description
   89    * The top-level directive for this group if present, otherwise null.
   90    */
   91   get formDirective(): Form|null { return this._parent ? this._parent.formDirective : null; }
   92 
   93   /**
   94    * @description
   95    * The synchronous validators registered with this group.
   96    */
   97   get validator(): ValidatorFn|null { return composeValidators(this._validators); }
   98 
   99   /**
  100    * @description
  101    * The async validators registered with this group.
  102    */
  103   get asyncValidator(): AsyncValidatorFn|null {
  104     return composeAsyncValidators(this._asyncValidators);
  105   }
  106 
  107   /** @internal */
  108   _checkParentType(): void {}
  109 }