这是我的HTML表单
<form ng-submit='create()'>
..
.
.
<input type='file' ng-model='logo' accept="image/*">
</form>
这是我的控制者:
$scope.create = function () {
$scope.Ent = {}
$scope.Ent.logo = $scope.logo;
答案 0 :(得分:1)
ng-model
无法使用输入类型&#39;文件。使用自定义指令绑定它
.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
}
}]);
将范围变量分配给fileread
属性
<form ng-submit='create()'>
..
.
.
<input type='file' fileread='logo' accept="image/*">
</form>