上載文件後,表格不清晰。如何在angularjs中上傳s3桶中的文件後清除表單輸入?
<div class="aboutFile">
<input type="file" name="file" fileread="vm.file" class="form-control" ng-model="vm.file">
<div class="create-component--perma-bg">
<i class="fa fa-plus-square-o" aria-hidden="true"></i>
<span ng-if="!vm.file.name">Add File </span>
<span ng-if="vm.file.name">{{vm.file.name}}</span>
</div>
<button type="button" class="btn btn-info bgChangeBtnInfo" ng-
click="vm.upload(vm.file)" ng-disabled="!vm.file"> Upload</button>
</div>
vm.upload
方法調用。
vm.upload = (fileObj) =>{
vm.call("saveSlideFile", vm.slideObject, (error, result) => {
if (!error) {
vm.file={};
console.log('File saved successfully');
}
})
}
fileread
指令
angular.module('livePoll')
.directive("fileread", [function() {
return {
scope: {
fileread: "="
},
link: function(scope,element, attributes){
$('.button-collapse').sideNav();
element.bind("change", function (event) {
scope.$apply(function() {
scope.fileread = event.target.files[0];
scope.$parent.fileread = scope.fileread;
});
})
}};
}]
你的指令改變只在'change'事件模型,但不清除該字段時從父控制器模型的變化。看看[這個答案和可能的指令實現](https://stackoverflow.com/a/44517492/4222181)。 –