大佬教程收集整理的这篇文章主要介绍了形式 – Angular 2 |如何在FormControl中处理输入类型文件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@Directive({ SELEctor: 'input[type=file]',providers: [ { provide: NG_VALUE_ACCESSOR,useExisTing: FileValueAccessorDirective,multi: true } ] }) export class FileValueAccessorDirective implements ControlValueAccessor { onChange; @HostListener('change',['$event.target.value']) _handleInput(event) { this.onChange(event); } constructor(private element: ElementRef,private render: Renderer2) { } writeValue(value: any) { const normalizedValue = value == null ? '' : value; this.render.setProperty(this.element.nativeElement,'value',normalizedvalue); } registerOnChange(fn) { this.onChange = fn; } registerOnTouched(fn: any) { } nOnDestroy() { } }@H_674_5@然后你就可以得到这样的更新: @H_674_5@
@Component({ modulEID: module.id,SELEctor: 'my-app',template: ` <h1>@R_801_11423@lo {{name}}</h1> <h3>File path is: {{path}}</h3> <input type="file" [formControl]="ctrl"> ` }) export class AppComponent { name = 'Angular'; path = ''; ctrl = new FormControl(''); ngOnInit() { this.ctrl.valueChanges.subscribe((v) => { this.path = v; }); } }
以上是大佬教程为你收集整理的形式 – Angular 2 |如何在FormControl中处理输入类型文件?全部内容,希望文章能够帮你解决形式 – Angular 2 |如何在FormControl中处理输入类型文件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。