0
我正在創建一個函數,以便我可以通過使用AngularJS將文件上傳到我的服務器。在瀏覽過程中,我在daniel farid上看到了github上的這個驚人的作品(鏈接 - https://github.com/danialfarid/ng-file-upload) 但是問題在於它對我來說太多瞭解。我從更基本的東西開始。 我很高興收到你的回覆。謝謝什麼是fileAPI?我如何以角度使用它?
我正在創建一個函數,以便我可以通過使用AngularJS將文件上傳到我的服務器。在瀏覽過程中,我在daniel farid上看到了github上的這個驚人的作品(鏈接 - https://github.com/danialfarid/ng-file-upload) 但是問題在於它對我來說太多瞭解。我從更基本的東西開始。 我很高興收到你的回覆。謝謝什麼是fileAPI?我如何以角度使用它?
嘗試在控制器中使用此指令。
app.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function() {
scope.$apply(function() {
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
的Html
<input type="file" name="file" class="file-input-wrapper btn btn-default btn-primary" file-model="uploadFile" id="control" />
,同時要回你的控制器: 上傳的文件將在該$scope.uploadFile
你有一個具體問題是可用? –