对于文件输入,我遇到了onchange事件的问题。下面是我的代码:
Html:
<input type="file" kendo-upload k-options="uploadOptions" id="fileInput" onchange="fileUploaded(event)"/>Angularjs代码-使用Typescript。
$scope.fileUploaded = (event) => {
console.log("Testing file upload");
var reader = new FileReader();
var target = event.target || event.srcElement;
reader.onload = function(e) {
$scope.$apply(function() {
$scope.readFile = reader.result;
});
};
var file = target.files[0];
reader.readAsText(file);
};我试着遵循这一点,并做出相应的改变,但仍然有问题。Pass angularJS $index into onchange
我是这样改变的。
<input type="file" kendo-upload k-options="uploadOptions" id="fileInput" onchange="angular.element(this).scope().fileUploaded(this)">我得到了这个错误。未捕获TypeError:未定义不是函数。onchange
当我尝试使用ng-change时,我遇到了这个错误。
<div kendo-window="importFile" k-visible="false" k-modal="true" k-title="'Import File'"
k-min-width="450" k-max-width="450"
k-min-height="418" k-max-height="418">
<form kendo-validator="validator" ng-submit="validate($event)">
<li style="padding-bottom: 5px;">
<input type="file" kendo-upload k-options="uploadOptions" id="fileInput" ng-change="fileUploaded($event)"/>
</li>
</form>
</div>这在访问这个$scope.importFile.center()时会给出错误;"TypeError: Cannot read property‘'center’of undefined“,如果我使用ng-click,效果会很好。
在这方面的任何帮助都是非常感谢的。
谢谢!
发布于 2016-03-06 01:16:16
在这种情况下不能使用ngChange,因为ngChange总是需要ngModel,而ngModel不能处理输入类型的文件。此外,您不能使用onchange直接访问绑定到$scope的函数。相反,请使用以下内容:
onchange="angular.element(this).scope().fileUploaded($event)"https://stackoverflow.com/questions/35816670
复制相似问题