角文件输入更改事件根本不发射
是否有人使用了具有Angular的文件输入。当声明为(更改)时,我无法将更改事件发射,但是当使用Onchange时,它可以使用,但不能使用Angular方法。有人成功使用过(变更)事件吗?不知道我在这里缺少什么。
这有效...
<input hidden mat-input onclick="this.value = null" onchange=”alert(‘works’)” #fileInput type="file">
这不起作用...
<input hidden mat-input onclick="this.value = null" (change)=”alert(‘works’)” #fileInput type="file">
Has anyone used a file input with Angular. I'm not able to get the change event to fire when declared as (change), but when using onchange it works but not with the angular method. Has anyone successfully used (change) event? Not sure what I'm missing here.
This works...
<input hidden mat-input onclick="this.value = null" onchange=”alert(‘works’)” #fileInput type="file">
This doesn't work...
<input hidden mat-input onclick="this.value = null" (change)=”alert(‘works’)” #fileInput type="file">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法访问模板中的全局方法。要解决此问题,您可以添加链接到窗口对象的属性:
并从模板调用它:
&lt; input(change)=“ window.alert('test')” type =“ file”&gt;
另一种方法是在组件方法中使用全局方法:
html:html:
&lt; input (更改)=“ testMethod('test')” type =“ file”&gt;
note :另外,请使用正确的报价标记:
“'''''
,不是:“''”
You don't have access to global methods in templates. To fix this you can add a property linked to the Window object:
and call it from the template:
<input (change)="window.alert('test')" type="file">
Another approach is to use global methods in component methods:
Html:
<input (change)="testMethod('test')" type="file">
Note: also please use proper quotation marks:
"''"
, not:”‘‘”