星空网 > 软件开发 > Java

angularjs input上传图片前获取图片的Size

首先我们需要一个指令来追踪input的change。ngChage不适用input[file]。

app.directive("fileread", [function () {
return {
scope: {
selectedFile: "=",
changed: '&'
},
link: function(scope, element, attributes) {
element.bind("change", function(changeEvent) {
scope.$apply(function() {
scope.selectedFile = changeEvent.target.files[0];
// or all selected files:
// scope.fileread = changeEvent.target.files;
console.log('file selected.');
if (scope.changed()) {
scope.changed()(scope.selectedFile);
}
});
});
}
};
}]);

然后在controller里定义file的变量跟change绑定的function。

$scope.showFileSelectBox = function () {
$("#imgSelectInput").click();
};

$scope.imageSelected = function(file) {
var image;

if (file) {

image = new Image();

image.onload = function () {

$scope.editObj.Width = this.width;
$scope.editObj.Height = this.height;
};

image.src = $window.URL.createObjectURL(file);

}
};

然后是html

<button type="button"  ng-click="showFileSelectBox()">上传</button>
<input type="file" accept="image/*" fileread selectedfile="selectedImgFile" id="imgSelectInput" changed="imageSelected" />




原标题:angularjs input上传图片前获取图片的Size

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

DTC品牌出海系列之独立站营销工具及流量插件分析:https://www.kjdsnews.com/a/538642.html
飓风艾达登录美国,亚马逊平台保护受其影响的卖家:https://www.kjdsnews.com/a/538643.html
TikTok催化新的侵权预警!注意产权排查:https://www.kjdsnews.com/a/538644.html
货代最赚钱?海运暴涨的根源是这一行业乱象!:https://www.kjdsnews.com/a/538645.html
亚马逊“清库存”方法大全,赶紧收藏:https://www.kjdsnews.com/a/538646.html
7款不应错过的Facebook广告监控工具:https://www.kjdsnews.com/a/538647.html
温州旧货市场有玻璃柜卖吗?:https://www.vstour.cn/a/411246.html
如何用摄影作品表现“芳草鲜美,落英缤纷”的:https://www.vstour.cn/a/411247.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流