Ng-“<inputtype=”file“/>的模型(带有指令演示)我尝试在输入标记上使用ng模型,并输入文件:<input type="file" ng-model="vm.uploadme" />但是在选择了一个文件之后,在控制器中,$scope e.vm.upadme仍然是未定义的。如何在控制器中获取选定的文件?
3 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
.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]);
});
}
}}]);<input type="file" fileread="vm.uploadme" />
.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
scope.$apply(function () {
scope.fileread = changeEvent.target.files[0];
// or all selected files:
// scope.fileread = changeEvent.target.files;
});
});
}
}}]);
慕仙森
TA贡献1827条经验 获得超8个赞
$scope.uploadme = {};$scope.uploadme.src = "";<input type="file" fileread="uploadme.src"/> <input type="text" ng-model="uploadme.src"/>
- 3 回答
- 0 关注
- 768 浏览
添加回答
举报
0/150
提交
取消
