当前位置: 首页>>代码示例>>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;未经允许,请勿转载。