javascript 如何在文件输入中捕获 ngchange 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26640439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to catch ngchange event in a file input
提问by user2167582
I have a file input
我有一个文件输入
<input type="file" ng-change="action()">
<input type="file" ng-change="action()">
Now in my controller I dont want to do selectors and stuff. so I just have
现在在我的控制器中,我不想做选择器之类的事情。所以我只有
$scope.action = () ->
...
However, I want a certain behavior such that as long as user selects a File the $scope.action is called, instead of onchange is there onselect event in angular?
但是,我想要某种行为,只要用户选择一个文件,就会调用 $scope.action,而不是 onchange 是否有 onselect 事件?
回答by Harutyun Abgaryan
Use thisss
用这个
<input ng-model="photo"
onchange="angular.element(this).scope().file_changed(this)"
type="file" accept="image/*" />
$scope.file_changed = function(element, $scope) {
$scope.$apply(function(scope) {
});
});