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" />

  • 相关阅读:
    mem 预留内存
    关于内核反汇编,同时显示源文件
    读些笔记
    platform设备驱动
    glut 右键子菜单
    获取HINSTANCE
    window窗口样式style
    opengl 直线拾取
    glut弹出式菜单
    读取大恒采集卡c++代码
  • 原文地址:https://www.cnblogs.com/kklldog/p/4861221.html
Copyright © 2011-2022 走看看