[英]How to trigger onchange input of type file with view model in Angular
I am using input of type file to open file and trigger a function on change like this. 我正在使用类型文件的输入来打开文件并像这样更改时触发功能。
<input type="file" multiple="multiple" class="fileUpload"
onchange="angular.element(this).scope().fileOpened(this)" />
my function is like this right now. 我的功能现在就是这样
$scope.fileOpened = function(data) {
// ...
}
it is working fine, but I want to do it in different way. 它工作正常,但我想用其他方式来做。 In my controller, I have create a view Modal like 在我的控制器中,我创建了一个模态视图
var vm = this;
and initializing all variables and function with that view model like 并使用该视图模型初始化所有变量和函数,例如
vm.fileOpened = fileOpened;
function fileOpened() {
}
Now how to trigger it with onchange event, I have tried it like this, but give an error. 现在如何使用onchange事件触发它,我已经尝试过这样,但是给出了错误。
onchange="angular.element(this).vm.fileOpened(this)"
Try 尝试
angular.element(this).scope().vm.fileOpened(this);
and 和
vm.fileOpened = function(data) {
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.