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


TypeScript FormControl.setErrors方法代碼示例

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


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

示例1: it

 it('should unset error when values are equal', () => {
   y.setErrors({ match: true });
   CdValidators.match('x', 'y')(form);
   expect(x.hasError('match')).toBeFalsy();
   expect(y.hasError('match')).toBeFalsy();
   expect(y.valid).toBeTruthy();
 });
開發者ID:yanghonggang,項目名稱:ceph,代碼行數:7,代碼來源:cd-validators.spec.ts

示例2: it

 it('should work for control with error', () => {
     let control: FormControl = new FormControl('');
     control.setErrors({ oldError: 'test', newError: 'test' });
     let validated = AbstractControlUtil.removeError(control, 'newError');
     expect(control.hasError('newError')).toBeFalsy();
     expect(control.hasError('oldError')).toBeTruthy();
 });
開發者ID:Nightapes,項目名稱:ng2-validators,代碼行數:7,代碼來源:abstract-control-util.spec.ts

示例3: it

      it('should reset the errors and validity when the value changes', () => {
        const c = new FormControl('someValue', Validators.required);

        c.setErrors({'someError': true});
        c.setValue('');

        expect(c.errors).toEqual({'required': true});
      });
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:8,代碼來源:form_control_spec.ts

示例4: it

    it("should create error messages", () => {

        let errorMessages,
            testControl: FormControl = new FormControl(),
            testModel: DynamicFormControlModel = new DynamicInputModel({
                id: "testModel",
                minLength: 5,
                errorMessages: {
                    required: "Field is required",
                    minLength: "Field must contain at least {{ minLength }} characters",
                    custom1: "Field {{ id }} has a custom error",
                    custom2: "Field has a custom error: {{ validator.param }}"
                }
            });

        errorMessages = service.createErrorMessages(testControl, testModel);
        expect(errorMessages.length).toBe(0);

        testControl.setErrors({required: true, minlength: 5});

        errorMessages = service.createErrorMessages(testControl, testModel);
        expect(errorMessages.length).toBe(2);
        expect(errorMessages[0]).toEqual((testModel.errorMessages as any)["required"]);
        expect(errorMessages[1]).toEqual("Field must contain at least 5 characters");

        testControl.setErrors({custom1: true});

        errorMessages = service.createErrorMessages(testControl, testModel);
        expect(errorMessages.length).toBe(1);
        expect(errorMessages[0]).toEqual(`Field ${testModel.id} has a custom error`);

        testControl.setErrors({custom2: {param: 42}});

        errorMessages = service.createErrorMessages(testControl, testModel);
        expect(errorMessages.length).toBe(1);
        expect(errorMessages[0]).toEqual("Field has a custom error: 42");
    });
開發者ID:thanhdevapp,項目名稱:ng-dynamic-forms,代碼行數:37,代碼來源:dynamic-form-validation.service.spec.ts

示例5: it

 it('should keep other existing errors', () => {
   y.setErrors({ match: true, notUnique: true });
   CdValidators.match('x', 'y')(form);
   formHelper.expectValid('x');
   formHelper.expectError('y', 'notUnique');
 });
開發者ID:leseb,項目名稱:ceph,代碼行數:6,代碼來源:cd-validators.spec.ts


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