我的html表单如下:
<input type="file" (change)="fileChangeEvent($event)" placeholder="Upload file" />
这很好。当我单击输入字段并选择一个文件并将其分配给angular2-typescript应用程序中的变量时,控制台会报告错误。
public base64Image: File;
fileChangeEvent(fileInput: any){
this.base64Image = fileInput.target.files[0]; <-- error reported here
}
浏览器中的控制台报告错误:
[object%20File]:1 GET http://localhost:8100/[object%20File] 404 (NotFound)Image (async)BrowserDomAdapter.setProperty @ browser_adapter.js:69DomRenderer.setElementProperty @ dom_renderer.js:161DebugDomRenderer.setElementProperty @ debug_renderer.js:92_View_SignupPage42.detectChangesInternal @ SignupPage4.template.js:452AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289AppView.detectContentChildrenChanges @ view.js:215_View_SignupPage40.detectChangesInternal @ SignupPage4.template.js:320AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289AppView.detectViewChildrenChanges @ view.js:220_View_SignupPage4_Host0.detectChangesInternal @ SignupPage4_Host.template.js:43AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289AppView.detectContentChildrenChanges @ view.js:215_View_Nav0.detectChangesInternal @ Nav.template.js:39AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289AppView.detectViewChildrenChanges @ view.js:220_View_MyApp0.detectChangesInternal @ MyApp.template.js:206AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289AppView.detectViewChildrenChanges @ view.js:220AppView.detectChangesInternal @ view.js:211AppView.detectChanges @ view.js:200DebugAppView.detectChanges @ view.js:289ViewRef_.detectChanges @ view_ref.js:119(anonymous function) @ application_ref.js:361ApplicationRef_.tick @ application_ref.js:361(anonymous function) @ application_ref.js:267ZoneDelegate.invoke @ zone.js:323onInvoke @ ng_zone_impl.js:45ZoneDelegate.invoke @ zone.js:322Zone.run @ zone.js:216NgZoneImpl.runInner @ ng_zone_impl.js:76NgZone.run @ ng_zone.js:223(anonymous function) @ application_ref.js:267schedulerFn @ async.js:123SafeSubscriber.__tryOrUnsub @ Subscriber.js:225SafeSubscriber.next @ Subscriber.js:174Subscriber._next @ Subscriber.js:124Subscriber.next @ Subscriber.js:88Subject._finalNext @ Subject.js:128Subject._next @ Subject.js:120Subject.next @ Subject.js:77EventEmitter.emit @ async.js:112NgZone._checkStable @ ng_zone.js:141onLeave @ ng_zone.js:113onInvoke @ ng_zone_impl.js:48ZoneDelegate.invoke @ zone.js:322Zone.runGuarded @ zone.js:230NgZoneImpl.runInnerGuarded @ ng_zone_impl.js:78NgZone.runGuarded @ ng_zone.js:228outsideHandler @ dom_events.js:20ZoneDelegate.invokeTask @ zone.js:356Zone.runTask @ zone.js:256ZoneTask.invoke @ zone.js:423