在没有插件的情况下支持IE9的angularjs的多文件上传

时间:2015-01-13 05:29:16

标签: php angularjs

我正在寻找一种轻松且轻量级的方式来使用angular进行上传。 http://nervgh.github.io/pages/angular-file-upload/examples/simple/

喜欢这个上传。更难。所以我想要轻松一个。

1 个答案:

答案 0 :(得分:0)

Check out "http://stackoverflow.com/a/20506037/1632286" This link consist all the posible ways for angular :-)

I did it like this :-
Here is the code i used in my project may be it help you.

HTML:

    <form role="form" name="myForm" ng-submit="submitCuisine()" novalidate>
                <div class="form-group">
                   <label for="description">Image</label> 
                   <input type="file"  file-input="files" name="file"/>
                </div>  
                <button class="btn btn-primary" type="submit"> Submit</button>
            </form>

Controller:

    $scope.submitCuisine=function(){

            var fd=new FormData();
            angular.forEach($scope.files,function(file){
                fd.append('file',file);
            })
            $http.post('admin/managecuisineAdd',fd,{
                transformRequest:angular.identity,
                headers:{'Content-type':undefined}
            }).success(function(data){
                $scope.message="Successfully"
            });

    }

Directive:

    myApp.directive("fileInput",['$parse',function($parse){
        return{
            restrict:'A',
            link:function(scope,ele,attrs){
                ele.bind('change',function(){
                    $parse(attrs.fileInput).
                    assign(scope,ele[0].files)
                    scope.$apply()
                });
            }
        }
    }]);
相关问题