我有一個粗略的去一點點通過角上傳文件,並在下面的解決方案解決:角文件上傳立即發生電平變化
$scope.uploadFile = function(files) {
var fd = new FormData();
//Take the first selected file
fd.append("file", files[0]);
console.log($scope.files);
$http.post('../resource/editor', fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).then(function(data){
//this keeps the user from having to refresh the page
DataContext.getEditors().then(function(data){
$scope.myData = data;
});
}).catch(function(reason){
});
};
<form name="myForm" >
<input type="file" name="file" onchange="angular.element(this).scope().uploadFile(this.files)"/>
<input type="submit" ng-click="uploadFile()" value='Submit'/>
</form>
目前的行爲是隻要用戶選擇一個文件,該文件開始上傳。我的意圖是,用戶將上傳文件的按鈕的點擊事件。我錯過了什麼來完成這件事?