fix(forms): remove deprecated forms APIs (#10624)

BREAKING CHANGE:

The deprecated forms APIs in @angular/common have been removed. Please update to the new forms API in @angular/forms. See angular.io for more information.
This commit is contained in:
Kara
2016-08-11 20:40:46 -07:00
committed by vikerman
parent 3466232f8b
commit 7606c96c80
49 changed files with 52 additions and 6818 deletions

View File

@ -257,15 +257,10 @@ export abstract class AbstractControl {
this._updateControlsErrors(emitEvent);
}
/**
* @deprecated - use get() instead
*/
find(path: Array<string|number>|string): AbstractControl { return _find(this, path, '/'); }
get(path: Array<string|number>|string): AbstractControl { return _find(this, path, '.'); }
getError(errorCode: string, path: string[] = null): any {
var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.find(path) : this;
var control = isPresent(path) && !ListWrapper.isEmpty(path) ? this.get(path) : this;
if (isPresent(control) && isPresent(control._errors)) {
return StringMapWrapper.get(control._errors, errorCode);
} else {
@ -432,18 +427,6 @@ export class FormControl extends AbstractControl {
this.setValue(value, options);
}
/**
* @deprecated Please use setValue() instead.
*/
updateValue(value: any, options: {
onlySelf?: boolean,
emitEvent?: boolean,
emitModelToViewChange?: boolean,
emitViewToModelChange?: boolean
} = {}): void {
this.setValue(value, options);
}
reset(value: any = null, {onlySelf}: {onlySelf?: boolean} = {}): void {
this.markAsPristine({onlySelf: onlySelf});
this.markAsUntouched({onlySelf: onlySelf});

View File

@ -365,66 +365,6 @@ export function main() {
}));
});
// deprecated function
// TODO(kara): remove these tests when updateValue is removed
describe('updateValue', () => {
var g: any /** TODO #9100 */, c: any /** TODO #9100 */;
beforeEach(() => {
c = new FormControl('oldValue');
g = new FormGroup({'one': c});
});
it('should update the value of the control', () => {
c.updateValue('newValue');
expect(c.value).toEqual('newValue');
});
it('should invoke ngOnChanges if it is present', () => {
var ngOnChanges: any /** TODO #9100 */;
c.registerOnChange((v: any /** TODO #9100 */) => ngOnChanges = ['invoked', v]);
c.updateValue('newValue');
expect(ngOnChanges).toEqual(['invoked', 'newValue']);
});
it('should not invoke on change when explicitly specified', () => {
var onChange: any /** TODO #9100 */ = null;
c.registerOnChange((v: any /** TODO #9100 */) => onChange = ['invoked', v]);
c.updateValue('newValue', {emitModelToViewChange: false});
expect(onChange).toBeNull();
});
it('should update the parent', () => {
c.updateValue('newValue');
expect(g.value).toEqual({'one': 'newValue'});
});
it('should not update the parent when explicitly specified', () => {
c.updateValue('newValue', {onlySelf: true});
expect(g.value).toEqual({'one': 'oldValue'});
});
it('should fire an event', fakeAsync(() => {
c.valueChanges.subscribe(
{next: (value: any) => { expect(value).toEqual('newValue'); }});
c.updateValue('newValue');
tick();
}));
it('should not fire an event when explicitly specified', fakeAsync(() => {
c.valueChanges.subscribe({next: (value: any) => { throw 'Should not happen'; }});
c.updateValue('newValue', {emitEvent: false});
tick();
}));
});
describe('reset()', () => {
let c: FormControl;
@ -1878,41 +1818,6 @@ export function main() {
}));
});
describe('find', () => {
it('should return null when path is null', () => {
var g = new FormGroup({});
expect(g.find(null)).toEqual(null);
});
it('should return null when path is empty', () => {
var g = new FormGroup({});
expect(g.find([])).toEqual(null);
});
it('should return null when path is invalid', () => {
var g = new FormGroup({});
expect(g.find(['one', 'two'])).toEqual(null);
});
it('should return a child of a control group', () => {
var g = new FormGroup({
'one': new FormControl('111'),
'nested': new FormGroup({'two': new FormControl('222')})
});
expect(g.find(['nested', 'two']).value).toEqual('222');
expect(g.find(['one']).value).toEqual('111');
expect(g.find('nested/two').value).toEqual('222');
expect(g.find('one').value).toEqual('111');
});
it('should return an element of an array', () => {
var g = new FormGroup({'array': new FormArray([new FormControl('111')])});
expect(g.find(['array', 0]).value).toEqual('111');
});
});
describe('get', () => {
it('should return null when path is null', () => {
var g = new FormGroup({});

View File

@ -431,8 +431,8 @@ export function main() {
fixture.detectChanges();
tick();
form.find('login').valueChanges.subscribe(
() => { expect(form.find('login').dirty).toBe(true); });
form.get('login').valueChanges.subscribe(
() => { expect(form.get('login').dirty).toBe(true); });
const loginEl = fixture.debugElement.query(By.css('input')).nativeElement;
loginEl.value = 'newValue';
@ -460,10 +460,10 @@ export function main() {
loginEl.value = 'newValue';
dispatchEvent(loginEl, 'input');
expect(form.find('login').pristine).toBe(false);
expect(form.get('login').pristine).toBe(false);
form.find('login').valueChanges.subscribe(
() => { expect(form.find('login').pristine).toBe(true); });
form.get('login').valueChanges.subscribe(
() => { expect(form.get('login').pristine).toBe(true); });
dispatchEvent(formEl, 'reset');
});