Created
February 29, 2016 22:28
-
-
Save Maks3w/8a02cc0f7745335695f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Directive, forwardRef, Provider} from "angular2/core"; | |
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from "angular2/common"; | |
import {CONST_EXPR} from "angular2/src/facade/lang"; | |
const FILE_VALUE_ACCESSOR = CONST_EXPR( | |
new Provider(NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => FileControlValueAccessor), multi: true}) | |
); | |
/** | |
* The accessor for listening to changes that is used by the | |
* {@link NgModel}, {@link NgFormControl}, and {@link NgControlName} directives. | |
* | |
* ### Example | |
* ``` | |
* <input type="file" [(ngModel)]="video"> | |
* ``` | |
*/ | |
@Directive( | |
{ | |
selector: 'input[type=file][ngControl],input[type=file][ngFormControl],input[type=file][ngModel]', | |
host: {'(change)': 'onChange($event.target.files)', '(blur)': 'onTouched()'}, | |
bindings: [FILE_VALUE_ACCESSOR] | |
} | |
) | |
export class FileControlValueAccessor implements ControlValueAccessor { | |
onChange = (_: any) => {}; | |
onTouched = () => {}; | |
writeValue(value: any): void { | |
} | |
registerOnChange(fn: () => any): void { | |
this.onChange = fn; | |
} | |
registerOnTouched(fn: () => any): void { | |
this.onTouched = fn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would these import statements be written with the latest version of Angular? (i.e. @angular/core and @angular/common don't work)
Thanks