javascript - Angular 从模板选择器中获取 $event
问题描述
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<input type="file" #myFile multiple />
<button (click)="onDelete(myFile.event)">DeleteFiles</button>
在上面myFile.event
返回未定义!如何myFile
通过单击按钮获取 $event,我只需要从用户选择中删除一个文件。
解决方案
我认为您实际上不需要任何$event
. 我认为您正在寻找这样的东西:
<input type="file" #myFile multiple>
<button (click)="onDelete(myFile.files)">DeleteFiles</button>
或者:
<input type="file" #myFile multiple>
<button (click)="onDelete(myFile.value)">DeleteFiles</button>
推荐阅读
- node.js - 请求在 Graphql 解析器中未定义,但在中间件中包含一些值。(节点,快递)
- lit-element - 获取道具后渲染
- javascript - 带有 if 语句的控制台日志 if option 等于 'Gel'
- flutter - 如何使用颤振在 Web 视图中显示可移植文档格式?
- devexpress - 在最终用户报表设计器 DevExpress 中添加外部数据源
- python - 如何始终使用“Atom”中的“脚本”运行相同的文件
- html - 在从 html 转换的 pdf 文件中获取意外的空格
- javascript - 我正在尝试将值从 servlet 文件传递到 javascript 文件,但我一直在获取 null 我在哪里做错了?
- c# - Automapper 缺少类型映射配置或不支持的映射?ASP>NET MVC
- audio - 如何在视频文件的音频中修改音乐音高并且仍然听起来自然