Angular 4 文件选择器

-1 events angular

我有一个项目,我需要通过按钮将文档添加到 API

但现在我只需要按钮打开文件选择器,让我选择文件并返回它的名称。

我已将此按钮分配给该事件。

那么有人可以帮我打开文件查找器的代码吗?我是 Angular 的初学者。

按钮:

<button (click)="myEvent($event)">Add Document</button>

事件:

 myEvent (event) {
 console.log(event); }
Run Code Online (Sandbox Code Playgroud)

预先感谢,大卫。

Fie*_*Dev 5

你需要

<input type="file"  multiple="multiple" (change)="change($event)">
Run Code Online (Sandbox Code Playgroud)

在你的 .ts 文件中你可以得到:

change(event:any) {
console.log(event.target.files);
}
Run Code Online (Sandbox Code Playgroud)