Skip to content

Instantly share code, notes, and snippets.

@Maks3w
Created February 29, 2016 22:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maks3w/8a02cc0f7745335695f3 to your computer and use it in GitHub Desktop.
Save Maks3w/8a02cc0f7745335695f3 to your computer and use it in GitHub Desktop.
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;
}
}
@Simpler1
Copy link

Simpler1 commented Jun 9, 2017

How would these import statements be written with the latest version of Angular? (i.e. @angular/core and @angular/common don't work)

Thanks

@TeodorKolev
Copy link

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment