@angular/forms#NgControl TypeScript Examples

The following examples show how to use @angular/forms#NgControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: checkbox-group.component.ts    From canopy with Apache License 2.0 6 votes vote down vote up
constructor(
    @Self() @Optional() private control: NgControl,
    private errorState: LgErrorStateMatcher,
    @Optional()
    @Host()
    @SkipSelf()
    private controlContainer: FormGroupDirective,
    private domService: LgDomService,
    private renderer: Renderer2,
    private hostElement: ElementRef,
  ) {
    this.variant = this.hostElement.nativeElement.tagName
      .split('-')[1]
      .toLowerCase() as CheckboxGroupVariant;

    if (this.control != null) {
      this.control.valueAccessor = this;
    }
  }
Example #2
Source File: permission-overwriter.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
constructor(
		public ngControl: NgControl,
		public permissionService: PermissionService,
		public permissionQuery: PermissionQuery,
		public sessionQuery: SessionQuery,
		public formBuilder: FormBuilder,
	) {
		ngControl.valueAccessor = this;
	}
Example #3
Source File: form-item.component.ts    From alauda-ui with MIT License 6 votes vote down vote up
mapControlStatus(control: NgControl) {
    return (
      this.parentForm
        ? combineLatest([
            control.statusChanges.pipe(startWith(control.status)),
            merge(
              this.parentForm.statusChanges.pipe(
                startWith(this.parentForm.status),
              ),
              this.parentForm.ngSubmit,
            ),
          ]).pipe(map(([status]: string[]) => status))
        : control.statusChanges
    ).pipe(
      map(
        (status: string) =>
          status === 'INVALID' && (control.dirty || this.parentForm?.submitted),
      ),
      publishRef(),
    );
  }
Example #4
Source File: permission-selector.component.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
constructor(
		public ngControl: NgControl,
		public permissionService: PermissionService,
		public permissionQuery: PermissionQuery,
		public sessionQuery: SessionQuery,
		public formBuilder: FormBuilder,
	) {
		ngControl.valueAccessor = this;
	}
Example #5
Source File: error-state-matcher.ts    From canopy with Apache License 2.0 6 votes vote down vote up
/**
   * This function is used to determine whether a specific form field is in an
   * error state.
   *
   * @param control -
   * The input control to check
   * @param controlContainer -
   * The form group that the input is part of
   * @return The error state of the property
   *
   * @example
   *     isControlInvalid(nameInput, registrationForm);
   *     // returns true
   */
  isControlInvalid(
    control: AbstractControl | NgControl,
    controlContainer?: FormGroupDirective,
  ): boolean {
    return !!(
      (control && control.invalid && control.touched && control.dirty) ||
      (controlContainer && controlContainer.submitted && control.invalid)
    );
  }
Example #6
Source File: np-mask.module.ts    From np-ui-lib with MIT License 6 votes vote down vote up
ngOnInit(): void {
    setTimeout(() => {
      this.control = this.injector.get(NgControl);

      if (!this.control || !this.control.valueAccessor) {
        return;
      }

      const originalWriteVal = this.control.valueAccessor.writeValue.bind(
        this.control.valueAccessor
      );
      this.control.valueAccessor.writeValue = (val: any) =>
        originalWriteVal(this._maskValue(val));

      const originalChange = (this.control.valueAccessor as any).onChange.bind(
        this.control.valueAccessor
      );
      this.control.valueAccessor.registerOnChange((val: any) =>
        originalChange(this._unmaskValue(val))
      );

      this._setVal(this._maskValue(this.control.value));
    }, 10);
  }
Example #7
Source File: file-input.component.ts    From angular-material-components with MIT License 6 votes vote down vote up
constructor(protected _elementRef: ElementRef<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>,
    protected _platform: Platform,
    private _cd: ChangeDetectorRef,
    @Optional() @Self() public ngControl: NgControl,
    @Optional() _parentForm: NgForm,
    @Optional() _parentFormGroup: FormGroupDirective,
    _defaultErrorStateMatcher: ErrorStateMatcher) {
    super(_defaultErrorStateMatcher, _parentForm, _parentFormGroup, ngControl);

    this.id = this.id;

    if (this.ngControl) {
      this.ngControl.valueAccessor = this;
    }

  }
Example #8
Source File: person-contact.component.ts    From forms-typed with MIT License 6 votes vote down vote up
constructor(@Self() @Optional() controlDirective: NgControl) {
    super(
      controlDirective,
      typedFormGroup<PersonContact>({
        name: typedFormControl<string>(),
        email: typedFormControl<string>()
      })
    );
  }
Example #9
Source File: fy-currency.component.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
ngOnInit() {
    this.ngControl = this.injector.get(NgControl);

    this.fg = this.fb.group({
      currency: [], // currency which is currently shown
      amount: [], // amount which is currently shown
      homeCurrencyAmount: [], // Amount converted to home currency
    });

    this.fg.valueChanges.subscribe((formValue) => {
      const value = {
        amount: null,
        currency: null,
        orig_amount: null,
        orig_currency: null,
      };

      if (formValue.currency !== this.homeCurrency) {
        value.currency = this.homeCurrency;

        value.orig_amount = +formValue.amount;
        value.orig_currency = formValue.currency;
        if (value.orig_currency === this.value.orig_currency) {
          value.amount = value.orig_amount * (this.value.amount / this.value.orig_amount);
        } else {
          value.amount = +formValue.homeCurrencyAmount;
        }
      } else {
        value.currency = this.homeCurrency;
        value.amount = formValue.amount && +formValue.amount;
      }

      if (!this.checkIfSameValue(value, this.innerValue)) {
        this.value = value;
      }
    });
  }
Example #10
Source File: radio-group.component.ts    From canopy with Apache License 2.0 6 votes vote down vote up
constructor(
    @Self() @Optional() private control: NgControl,
    private errorState: LgErrorStateMatcher,
    @Optional()
    @Host()
    @SkipSelf()
    private controlContainer: FormGroupDirective,
    private domService: LgDomService,
    private hostElement: ElementRef,
    private renderer: Renderer2,
  ) {
    this.variant = this.hostElement.nativeElement.tagName
      .split('-')[1]
      .toLowerCase() as RadioVariant;

    if (this.control != null) {
      this.control.valueAccessor = this;
    }
  }
Example #11
Source File: fy-currency.component.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
ngOnInit() {
    this.ngControl = this.injector.get(NgControl);

    this.fg = this.fb.group({
      currency: [], // currency which is currently shown
      amount: [], // amount which is currently shown
    });

    this.fg.valueChanges.subscribe((formValue) => {
      const value = {
        amount: null,
        currency: null,
      };

      if (formValue.amount !== null) {
        value.amount = +formValue.amount;
      }
      value.currency = formValue.currency;

      if (!this.checkIfSameValue(value, this.innerValue)) {
        this.value = value;
      }
    });
  }
Example #12
Source File: radio-button.component.ts    From canopy with Apache License 2.0 6 votes vote down vote up
constructor(
    @Self() @Optional() public control: NgControl,
    @Inject(forwardRef(() => LgRadioGroupComponent))
    private radioGroup: LgRadioGroupComponent,
    private errorState: LgErrorStateMatcher,
    @Optional()
    @Host()
    @SkipSelf()
    private controlContainer: FormGroupDirective,
    private renderer: Renderer2,
    private hostElement: ElementRef,
    private domService: LgDomService,
  ) {}
Example #13
Source File: route-selector.component.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
ngOnInit() {
    this.ngControl = this.injector.get(NgControl);

    this.form.controls.roundTrip.valueChanges.subscribe((roundTrip) => {
      if (!this.skipRoundTripUpdate) {
        if (this.formInitialized) {
          if (this.form.value.distance) {
            if (roundTrip) {
              this.form.controls.distance.setValue((+this.form.value.distance * 2).toFixed(2));
            } else {
              this.form.controls.distance.setValue((+this.form.value.distance / 2).toFixed(2));
            }
          }
        }
      } else {
        this.skipRoundTripUpdate = false;
      }
    });
  }
Example #14
Source File: checkbox-input.component.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
constructor(public ngControl: NgControl) {
		ngControl.valueAccessor = this;
	}
Example #15
Source File: fy-userlist.component.ts    From fyle-mobile-app with MIT License 5 votes vote down vote up
ngOnInit() {
    this.ngControl = this.injector.get(NgControl);
  }
Example #16
Source File: data-input.component.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
constructor(
		public ngControl: NgControl,
		private dynamicInputService: DynamicInputService
	) {
		ngControl.valueAccessor = this;
	}
Example #17
Source File: np-mask.module.ts    From np-ui-lib with MIT License 5 votes vote down vote up
private control: NgControl;
Example #18
Source File: control-value-accessor-connector.ts    From forms-typed with MIT License 5 votes vote down vote up
constructor(@Optional() @Self() private directive: NgControl, form: TypedFormGroup<T, C>) {
    if (directive) {
      directive.valueAccessor = this;
    }
    this.form = form;
  }
Example #19
Source File: route-selector.component.ts    From fyle-mobile-app with MIT License 5 votes vote down vote up
private ngControl: NgControl;
Example #20
Source File: time-input.component.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
constructor(public ngControl: NgControl) {
		ngControl.valueAccessor = this;
	}
Example #21
Source File: checkbox-group.component.spec.ts    From canopy with Apache License 2.0 5 votes vote down vote up
isControlInvalid(control: NgControl, form: FormGroupDirective) {
    return this.errorState.isControlInvalid(control, form);
  }
Example #22
Source File: textarea-input.component.ts    From radiopanel with GNU General Public License v3.0 5 votes vote down vote up
constructor(public ngControl: NgControl) {
		ngControl.valueAccessor = this;
	}
Example #23
Source File: toggle.component.spec.ts    From canopy with Apache License 2.0 5 votes vote down vote up
isControlInvalid(control: NgControl, form: FormGroupDirective) {
    return this.errorState.isControlInvalid(control, form);
  }
Example #24
Source File: phone-mask.directive.ts    From careydevelopmentcrm with MIT License 5 votes vote down vote up
constructor(public ngControl: NgControl) { }
Example #25
Source File: tags-input.component.ts    From alauda-ui with MIT License 5 votes vote down vote up
// 外层 FormControl,所有的校验逻辑针对输入数据
  controlContainer: NgControl;
Example #26
Source File: form.stories.ts    From canopy with Apache License 2.0 5 votes vote down vote up
isControlInvalid(control: NgControl, form: FormGroupDirective) {
    return this.errorState.isControlInvalid(control, form);
  }
Example #27
Source File: fy-currency.component.ts    From fyle-mobile-app with MIT License 5 votes vote down vote up
private ngControl: NgControl;
Example #28
Source File: sort-code.directive.ts    From canopy with Apache License 2.0 5 votes vote down vote up
constructor(private ngControl: NgControl) {}
Example #29
Source File: fy-location.component.ts    From fyle-mobile-app with MIT License 5 votes vote down vote up
ngOnInit() {
    this.ngControl = this.injector.get(NgControl);
  }