本文整理汇总了TypeScript中@angular/forms.AbstractControl.setValue方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AbstractControl.setValue方法的具体用法?TypeScript AbstractControl.setValue怎么用?TypeScript AbstractControl.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/forms.AbstractControl
的用法示例。
在下文中一共展示了AbstractControl.setValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handleTimeClearedEvent
handleTimeClearedEvent() {
if (this.control) {
this.model.resetMessage();
this.model.clientValid = true;
this.control.setValue('');
}
}
示例2: setValue
/**
* Changes the value of a control
*/
setValue(control: AbstractControl | string, value: any, markAsDirty?: boolean): AbstractControl {
control = this.getControl(control);
if (markAsDirty) {
control.markAsDirty();
}
control.setValue(value);
return control;
}
示例3: handleInvalidTimeEvent
handleInvalidTimeEvent(data: string) {
if (this.control) {
this.control.setValue('');
this.model.setInvalidTime();
this.model.clientValid = false;
this.control.setErrors({ [this.model.getMessage()]: true });
}
}
示例4: it
it('Inland Location Is Set: Form Should be Valid', () => {
inland.setValue('DEDUS');
fixture.detectChanges();
expect(component.form.valid).toBeTruthy();
expect(component.isInvalid()).toBeFalsy();
});
示例5: setValueIfChanged
setValueIfChanged(time: string) {
const oldValue = this.control.value;
const newValue = time ? time : '';
if (newValue !== oldValue) {
this.model.resetMessage();
this.model.clientValid = true;
this.control.setValue(newValue);
}
}
示例6: it
it('should have invalid CartesianPosition fields when 1 or 2 is changed in group', () => {
let x: AbstractControl = comp.cartesianPositionForm.controls['x'];
let y: AbstractControl = comp.cartesianPositionForm.controls['y'];
let z: AbstractControl = comp.cartesianPositionForm.controls['z'];
let xInvalid: HTMLInputElement = dom.querySelector('number-input[controlname="x"] small') as HTMLInputElement;
let yInvalid: HTMLInputElement = dom.querySelector('number-input[controlname="y"] small') as HTMLInputElement;
let zInvalid: HTMLInputElement = dom.querySelector('number-input[controlname="z"] small') as HTMLInputElement;
// Setting one or two of x,y,z should cause all to become required and others to be invalid
x.setValue(7);
fixture.detectChanges();
expect(x.valid).toBeTruthy();
expect(y.valid).toBeFalsy();
expect(z.valid).toBeFalsy();
expect(xInvalid.textContent).toEqual('');
expect(yInvalid.textContent).toContain('Field required');
expect(zInvalid.textContent).toContain('Field required');
y.setValue(77);
fixture.detectChanges();
expect(x.valid).toBeTruthy();
expect(y.valid).toBeTruthy();
expect(z.valid).toBeFalsy();
expect(xInvalid.textContent).toEqual('');
expect(yInvalid.textContent).toEqual('');
expect(zInvalid.textContent).toContain('Field required');
// Set them all and they should now be valid
z.setValue(777);
fixture.detectChanges();
expect(x.valid).toBeTruthy();
expect(y.valid).toBeTruthy();
expect(z.valid).toBeTruthy();
expect(xInvalid.textContent).toEqual('');
expect(yInvalid.textContent).toEqual('');
expect(zInvalid.textContent).toEqual('');
// take away all the values and they should be valid also
x.setValue(null);
y.setValue(null);
z.setValue(null);
fixture.detectChanges();
expect(x.valid).toBeTruthy();
expect(y.valid).toBeTruthy();
expect(z.valid).toBeTruthy();
expect(xInvalid.textContent).toEqual('');
expect(yInvalid.textContent).toEqual('');
expect(zInvalid.textContent).toEqual('');
});
示例7: fakeAsync
fakeAsync(() => {
x.setValue('xyz');
tick(500);
expect(x.hasError('notUnique')).toBeTruthy();
expect(x.valid).toBeFalsy();
})
示例8: it
it('should not error because of empty input', () => {
x.setValue('');
expect(x.hasError('notUnique')).toBeFalsy();
expect(x.valid).toBeTruthy();
});
示例9: dirty
/*
Ensures a programmatic change to an AbstractControl value is marked as dirty (and by default as touched)
prior to the change, properly invoking validation and the display of any validation errors.
*/
changeControlValue( control: AbstractControl, value: any, markTouched: boolean = true ) : void {
control.markAsDirty();
control.markAsTouched( markTouched );
control.setValue( value );
}