角JS文件上传文件上传、JS

2023-09-13 03:41:17 作者:狂,是我的个性

我是新来的角的js。我想用这个来上传文件。我用下面的链接

i am new to angular js. i want to upload file using this. i used following link

http://jsfiddle.net/jasonals/WEvwz/27/ ?upload.html

http://jsfiddle.net/jasonals/WEvwz/27/? upload.html

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://blueimp.github.com/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
<script src="http://blueimp.github.com/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<div ng-controller='TestCtrl'>
  <div>
      <input id="fileupload" type="file" name="files[]" data-url="/" multiple>
      <ul>
          <li ng-repeat="file in fileList">
              {{file.name}}
          </li>
      </ul>
  </div>

  <button ng-click='addButtonClicked()'>Add File</button>
</div>

controlller file.
$(document).ready(function(){
    $('#fileupload').fileupload({
        dataType: 'json'});
});

TestCtrl = function($scope){
    $scope.fileList = [];
    $('#fileupload').bind('fileuploadadd', function(e, data){
        // Add the files to the list
        numFiles = $scope.fileList.length
        for (var i=0; i < data.files.length; ++i) {
            var file = data.files[i];
        // .$apply to update angular when something else makes changes
        $scope.$apply(
            $scope.fileList.push({name: file.name})
            );
        }
        // Begin upload immediately
        data.submit();
    });
    $scope.addButtonClicked = function(){
        var numFiles = $scope.fileList.length;
        $scope.fileList.push({name: ('fileName' + numFiles)});
    }
}

但我无法使用该发布的URL。

but i am unable to post the url using this.

推荐答案

试试这个...

$(document).ready(function(){
    $('#fileupload').fileupload({
        dataType: 'json'});
});

TestCtrl = function($scope){
    $scope.fileList = [];
    $('#fileupload').bind('fileuploadadd', function(e, data){
            $scope.$apply(
            $scope.fileList.push({name: file.name})
            );   
        data.submit();
    });

}