Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to have a separate span which invokes the "browse" button on an input type=file. In internet explorer it is not working,

Code is given below

HTML

<span class="edit-btn" data-ng-click="callFileControl()" ></span>

  <input style="dispaly:none" name="selectFileControl" id="selectFileControl" type="file"  
                    onchange="angular.element(this).scope().setFiles(this)" />

ANGULAR

$scope.callFileControl = function () {
        $("#selectFileControl").click();
    };

$scope.setFiles = function (element) {
        $scope.$apply(function ($scope) {
            // Turn the FileList object into an Array
            $scope.files = [];
            for (var i = 0; i < element.files.length; i++) {
                var sFileExtension = element.files[i].name.split('.')[element.files[i].name.split('.').length - 1];
                if (sFileExtension == "jpg" || sFileExtension == "jpeg" || sFileExtension == "png") {
                    $scope.files.push(element.files[i]);
                    $scope.uploadFile();
                }
            }
        });
    };

In IE 9 "element.files" is undefined. but in Mozilla it working as expected.

Is there any way to fix this?

share|improve this question
1  
your $("#selectFileControl").click() is not a good practice :/ (using jquery selectors inside a controller) – sports Sep 18 '14 at 1:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.