zoukankan      html  css  js  c++  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" style="display: none" accept="image/*" fileread selectedfile="selectedImgFile" id="imgSelectInput" changed="imageSelected" />

  • 相关阅读:
    2020年秋招三星面试题
    物联网金融和互联网金融的区别与联系
    数据库事务的4种隔离级别
    Access-cookie之sqlmap注入
    SDL-软件安全开发周期流程
    图片马的制作
    ssrf内网端口爆破扫描
    逻辑漏洞_验证码绕过_密码找回漏洞
    平行越权与垂直越权
    xff注入
  • 原文地址:https://www.cnblogs.com/wangjie-01/p/4862620.html
Copyright © 2011-2022 走看看