當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。