您好,我是 Angular JS 的新手。我一直在尝试做一些事情,我有一个登录表单,其中我有一个文件输入类型,用户可以在其中上传他的图片。输入框是这样的
<input type="file" file-model="userPic"/>
所以,当我提交表单时,在 controller.js 文件中
console.log(userPic)
我得到文件名、大小、修改日期。但是我想在表单提交之前找到上传图片宽度和高度的尺寸。我还安装了 bower 组件,我在里面有 jquery 文件夹,我有 dimensions.js 文件,这有用吗?
我还尝试使用 .width() 来控制 console.log。为此我稍微更改了代码
<input type="file" file-model="userPic" id="userId"/>
并在表单提交的 controller.js 文件中
console.log($('#userId').width());
我试过了,但我得到的输出不正确。我将如何进行。
最佳答案
您需要使用 naturalWidth 和 naturalHeight:
$scope.userPic.naturalHeight();
$scope.userPic.naturalWidth();
关于javascript - 在图像上传时使用angularjs获取尺寸(宽度和高度)验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46411475/