當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript forms.AbstractControl類代碼示例

本文整理匯總了TypeScript中@angular/forms.AbstractControl的典型用法代碼示例。如果您正苦於以下問題:TypeScript AbstractControl類的具體用法?TypeScript AbstractControl怎麽用?TypeScript AbstractControl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AbstractControl類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: setValue

 const setPgNum = (pgs): AbstractControl => {
   setValue('poolType', 'erasure');
   const control = setValue('pgNum', pgs);
   fixture.detectChanges();
   fixture.debugElement.query(By.css('#pgNum')).nativeElement.dispatchEvent(new Event('blur'));
   return control;
 };
開發者ID:dillaman,項目名稱:ceph,代碼行數:7,代碼來源:pool-form.component.spec.ts

示例2: addError

 static addError(control: AbstractControl, errorId: string, value: any) {
     if (!control.errors) {
         control.setErrors({ [errorId]: value });
     } else if (!control.hasError(errorId)) {
         control.errors[errorId] = value;
     }
 }
開發者ID:Nightapes,項目名稱:ng2-validators,代碼行數:7,代碼來源:abstract-control-util.ts

示例3: setErrors

    protected setErrors(control: AbstractControl, errors: FormErrors): void {
        if (isPresent(errors.errors)) {
            let controlErrors = {};

            errors.errors.forEach((error) => {
                controlErrors[error] = true;
            });

            control.setErrors(controlErrors);
            control.markAsDirty({
                onlySelf: true
            });
        }

        if (isPresent(errors.children)) {
            for (let name in errors.children) {
                if (errors.children.hasOwnProperty(name)) {
                    let child = control.get(name);

                    if (null !== child) {
                        this.setErrors(child, errors.children[name]);
                    }
                }
            }
        }
    }
開發者ID:Invis1ble,項目名稱:assistant-client,代碼行數:26,代碼來源:abstract-form.ts

示例4: dateRangeValidator

export function dateRangeValidator(c: AbstractControl): {[key: string]: any} {
  // Get controls in group
  const startDateC = c.get('startDate');
  const startTimeC = c.get('startTime');
  const endDateC = c.get('endDate');
  const endTimeC = c.get('endTime');
  // Object to return if date is invalid
  const invalidObj = { 'dateRange': true };

  // If start and end dates are valid, can check range (with prefilled times)
  // Final check happens when all dates/times are valid
  if (startDateC.valid && endDateC.valid) {
    const checkStartTime = startTimeC.invalid ? '12:00 AM' : startTimeC.value;
    const checkEndTime = endTimeC.invalid ? '11:59 PM' : endTimeC.value;
    const startDatetime = stringsToDate(startDateC.value, checkStartTime);
    const endDatetime = stringsToDate(endDateC.value, checkEndTime);

    if (endDatetime >= startDatetime) {
      return null;
    } else {
      return invalidObj;
    }
  }
  return null;
}
開發者ID:connelb,項目名稱:fitwithlc,代碼行數:25,代碼來源:date-range.validator.ts

示例5:

export const passwordMatcher = (control: AbstractControl): {[key: string]: boolean} => {
  const password = control.get('password');
  const confirm = control.get('confirm');
  if (!password || !confirm) {
    return null;
  }
  return password.value === confirm.value ? null : { nomatch: true };
};
開發者ID:yurlovm,項目名稱:lab12,代碼行數:8,代碼來源:password-matcher.ts

示例6: it

 it('validates name', () => {
   hasError(form.get('name'), 'required');
   isValid(setValue('name', 'some-name'));
   component.info.pool_names.push('someExistingPoolName');
   hasError(setValue('name', 'someExistingPoolName'), 'uniqueName');
   hasError(setValue('name', 'wrong format with spaces'), 'pattern');
 });
開發者ID:dillaman,項目名稱:ceph,代碼行數:7,代碼來源:pool-form.component.spec.ts

示例7: it

 it('validates pgNum in creation mode', () => {
   formHelper.expectError(form.get('pgNum'), 'required');
   formHelper.setValue('poolType', 'erasure');
   formHelper.expectValid(setPgNum(-28));
   expect(form.getValue('pgNum')).toBe(1);
   formHelper.expectValid(setPgNum(15));
   expect(form.getValue('pgNum')).toBe(16);
 });
開發者ID:IlsooByun,項目名稱:ceph,代碼行數:8,代碼來源:pool-form.component.spec.ts

示例8: handleInvalidTimeEvent

 handleInvalidTimeEvent(data: string) {
     if (this.control) {
         this.control.setValue('');
         this.model.setInvalidTime();
         this.model.clientValid = false;
         this.control.setErrors({ [this.model.getMessage()]: true });
     }
 }
開發者ID:NakedObjectsGroup,項目名稱:NakedObjectsFramework,代碼行數:8,代碼來源:time-picker-facade.component.ts


注:本文中的@angular/forms.AbstractControl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。