feat(host): limits host properties to renames

This commit is contained in:
vsavkin
2015-06-22 08:21:03 -07:00
parent c1a494bc37
commit 92ffc465d6
8 changed files with 177 additions and 24 deletions

View File

@ -1,6 +1,7 @@
import {Directive, Renderer, ElementRef} from 'angular2/angular2';
import {NgControl} from './ng_control';
import {ControlValueAccessor} from './control_value_accessor';
import {isPresent} from 'angular2/src/facade/lang';
import {setProperty} from './shared';
/**
@ -20,12 +21,12 @@ import {setProperty} from './shared';
'(change)': 'onChange($event.target.checked)',
'(blur)': 'onTouched()',
'[checked]': 'checked',
'[class.ng-untouched]': 'cd.control?.untouched == true',
'[class.ng-touched]': 'cd.control?.touched == true',
'[class.ng-pristine]': 'cd.control?.pristine == true',
'[class.ng-dirty]': 'cd.control?.dirty == true',
'[class.ng-valid]': 'cd.control?.valid == true',
'[class.ng-invalid]': 'cd.control?.valid == false'
'[class.ng-untouched]': 'ngClassUntouched',
'[class.ng-touched]': 'ngClassTouched',
'[class.ng-pristine]': 'ngClassPristine',
'[class.ng-dirty]': 'ngClassDirty',
'[class.ng-valid]': 'ngClassValid',
'[class.ng-invalid]': 'ngClassInvalid'
}
})
export class CheckboxControlValueAccessor implements ControlValueAccessor {
@ -44,6 +45,21 @@ export class CheckboxControlValueAccessor implements ControlValueAccessor {
setProperty(this.renderer, this.elementRef, "checked", value);
}
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
}
registerOnChange(fn): void { this.onChange = fn; }
registerOnTouched(fn): void { this.onTouched = fn; }
}

View File

@ -1,7 +1,7 @@
import {Directive, Renderer, ElementRef} from 'angular2/angular2';
import {NgControl} from './ng_control';
import {ControlValueAccessor} from './control_value_accessor';
import {isBlank} from 'angular2/src/facade/lang';
import {isBlank, isPresent} from 'angular2/src/facade/lang';
import {setProperty} from './shared';
/**
@ -23,16 +23,17 @@ import {setProperty} from './shared';
'(input)': 'onChange($event.target.value)',
'(blur)': 'onTouched()',
'[value]': 'value',
'[class.ng-untouched]': 'cd.control?.untouched == true',
'[class.ng-touched]': 'cd.control?.touched == true',
'[class.ng-pristine]': 'cd.control?.pristine == true',
'[class.ng-dirty]': 'cd.control?.dirty == true',
'[class.ng-valid]': 'cd.control?.valid == true',
'[class.ng-invalid]': 'cd.control?.valid == false'
'[class.ng-untouched]': 'ngClassUntouched',
'[class.ng-touched]': 'ngClassTouched',
'[class.ng-pristine]': 'ngClassPristine',
'[class.ng-dirty]': 'ngClassDirty',
'[class.ng-valid]': 'ngClassValid',
'[class.ng-invalid]': 'ngClassInvalid'
}
})
export class DefaultValueAccessor implements ControlValueAccessor {
value: string = null;
onChange = (_) => {};
onTouched = () => {};
@ -47,6 +48,21 @@ export class DefaultValueAccessor implements ControlValueAccessor {
setProperty(this.renderer, this.elementRef, 'value', this.value);
}
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
}
registerOnChange(fn): void { this.onChange = fn; }
registerOnTouched(fn): void { this.onTouched = fn; }

View File

@ -1,6 +1,7 @@
import {Directive, Query, QueryList, Renderer, ElementRef} from 'angular2/angular2';
import {NgControl} from './ng_control';
import {ControlValueAccessor} from './control_value_accessor';
import {isPresent} from 'angular2/src/facade/lang';
import {setProperty} from './shared';
/**
@ -30,12 +31,12 @@ export class NgSelectOption {
'(input)': 'onChange($event.target.value)',
'(blur)': 'onTouched()',
'[value]': 'value',
'[class.ng-untouched]': 'cd.control?.untouched == true',
'[class.ng-touched]': 'cd.control?.touched == true',
'[class.ng-pristine]': 'cd.control?.pristine == true',
'[class.ng-dirty]': 'cd.control?.dirty == true',
'[class.ng-valid]': 'cd.control?.valid == true',
'[class.ng-invalid]': 'cd.control?.valid == false'
'[class.ng-untouched]': 'ngClassUntouched',
'[class.ng-touched]': 'ngClassTouched',
'[class.ng-pristine]': 'ngClassPristine',
'[class.ng-dirty]': 'ngClassDirty',
'[class.ng-valid]': 'ngClassValid',
'[class.ng-invalid]': 'ngClassInvalid'
}
})
export class SelectControlValueAccessor implements ControlValueAccessor {
@ -57,6 +58,21 @@ export class SelectControlValueAccessor implements ControlValueAccessor {
setProperty(this.renderer, this.elementRef, "value", value);
}
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
}
registerOnChange(fn): void { this.onChange = fn; }
registerOnTouched(fn): void { this.onTouched = fn; }