当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript forms.FormControl类代码示例

本文整理汇总了TypeScript中@angular/forms.FormControl的典型用法代码示例。如果您正苦于以下问题:TypeScript FormControl类的具体用法?TypeScript FormControl怎么用?TypeScript FormControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FormControl类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

    describe('reset()', () => {
      let c: FormControl;

      beforeEach(() => { c = new FormControl('initial value'); });

      it('should reset to a specific value if passed', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset('initial value');
        expect(c.value).toBe('initial value');
      });

      it('should not set the parent when explicitly specified', () => {
        const g = new FormGroup({'one': c});
        c.patchValue('newValue', {onlySelf: true});
        expect(g.value).toEqual({'one': 'initial value'});
      });

      it('should reset to a specific value if passed with boxed value', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset({value: 'initial value', disabled: false});
        expect(c.value).toBe('initial value');
      });

      it('should clear the control value if no value is passed', () => {
        c.setValue('new value');
        expect(c.value).toBe('new value');

        c.reset();
        expect(c.value).toBe(null);
      });

      it('should update the value of any parent controls with passed value', () => {
        const g = new FormGroup({'one': c});
        c.setValue('new value');
        expect(g.value).toEqual({'one': 'new value'});

        c.reset('initial value');
        expect(g.value).toEqual({'one': 'initial value'});
      });

      it('should update the value of any parent controls with null value', () => {
        const g = new FormGroup({'one': c});
        c.setValue('new value');
        expect(g.value).toEqual({'one': 'new value'});

        c.reset();
        expect(g.value).toEqual({'one': null});
      });

      it('should mark the control as pristine', () => {
        c.markAsDirty();
        expect(c.pristine).toBe(false);

        c.reset();
        expect(c.pristine).toBe(true);
      });

      it('should set the parent pristine state if all pristine', () => {
        const g = new FormGroup({'one': c});
        c.markAsDirty();
        expect(g.pristine).toBe(false);

        c.reset();
        expect(g.pristine).toBe(true);
      });

      it('should not set the parent pristine state if it has other dirty controls', () => {
        const c2 = new FormControl('two');
        const g = new FormGroup({'one': c, 'two': c2});
        c.markAsDirty();
        c2.markAsDirty();

        c.reset();
        expect(g.pristine).toBe(false);
      });

      it('should mark the control as untouched', () => {
        c.markAsTouched();
        expect(c.untouched).toBe(false);

        c.reset();
        expect(c.untouched).toBe(true);
      });

      it('should set the parent untouched state if all untouched', () => {
        const g = new FormGroup({'one': c});
        c.markAsTouched();
        expect(g.untouched).toBe(false);

        c.reset();
        expect(g.untouched).toBe(true);
      });

      it('should not set the parent untouched state if other touched controls', () => {
        const c2 = new FormControl('two');
        const g = new FormGroup({'one': c, 'two': c2});
//.........这里部分代码省略.........
开发者ID:lucduong,项目名称:angular,代码行数:101,代码来源:form_control_spec.ts

示例2: ngOnInit

 ngOnInit() {
   this.validator = equalTo(this.equalTo);
 }
开发者ID:diandsonc,项目名称:ng2-validation,代码行数:3,代码来源:directive.ts

示例3: it

 it('should not set the parent when explicitly specified', () => {
   c.patchValue('newValue', {onlySelf: true});
   expect(g.value).toEqual({'one': 'oldValue'});
 });
开发者ID:lucduong,项目名称:angular,代码行数:4,代码来源:form_control_spec.ts

示例4: it

 it('should unset error when values are equal', () => {
   y.setErrors({ match: true });
   CdValidators.match('x', 'y')(form);
   formHelper.expectValid('x');
   formHelper.expectValid('y');
 });
开发者ID:IlsooByun,项目名称:ceph,代码行数:6,代码来源:cd-validators.spec.ts

示例5:

	ngAfterViewInit(): void {
		this.control.updateValueAndValidity(this.value || undefined);

		super.ngAfterViewInit();
	}
开发者ID:JamieBowen,项目名称:TypeScript-Angular-Components,代码行数:5,代码来源:validationInput.ts


注:本文中的@angular/forms.FormControl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。