Angularjs 文件未传递到角JS中的ng文件选择
我试图将一个文件从html视图传递到angular controller,为此我在视图中使用ng file select。我的视图代码如下所示:Angularjs 文件未传递到角JS中的ng文件选择,angularjs,asp.net-web-api,Angularjs,Asp.net Web Api,我试图将一个文件从html视图传递到angular controller,为此我在视图中使用ng file select。我的视图代码如下所示: <div ng-controller="fileController"> <input type="file" ng-model="fibQuestion.fibContentLanguage.colUploadPaperUrl" name="PaperDocUrl" ng-file-select="onPaperFileS
<div ng-controller="fileController">
<input type="file" ng-model="fibQuestion.fibContentLanguage.colUploadPaperUrl" name="PaperDocUrl" ng-file-select="onPaperFileSelect($files)" onclick="this.value = null" id="forPracticalTestPaper" />
<div>
<input type="button" id="save" class="btn btn-success" value="Save" ng-click="PaperFileProcessing()" />
</div>
</div>
当我按下save按钮时,会调用函数PaperFileProcessing(),但是,var fileBank=$scope.uploadedPaper;显示未定义。我认为您的代码缺少某种“承诺”,无法等待文件完全上传,不是吗? 也许是这样的:
// returns a promise
upload.then(function(resp) {
// file is uploaded successfully
console.log('file ' + resp.config.data.file.name + 'is uploaded successfully. Response: ' + resp.data);
}, function(resp) {
// handle error
}, function(evt) {
// progress notify
console.log('progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ evt.config.data.file.name);
});
// returns a promise
upload.then(function(resp) {
// file is uploaded successfully
console.log('file ' + resp.config.data.file.name + 'is uploaded successfully. Response: ' + resp.data);
}, function(resp) {
// handle error
}, function(evt) {
// progress notify
console.log('progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ evt.config.data.file.name);
});