ng-file-upload无效

时间:2016-06-26 07:42:09

标签: javascript html angularjs ng-file-upload

我想输入图像并将其上传到本地计算机上的文件夹中。

HTML:

newid()

CONTROLLER:

enum class Fruit
{
    apple,
    banana,
    orange,
    pineapple,
    lemon,
};

bool operator<(Fruit l, Fruit r) 
{
    return true;
}

int main()
{
    Fruit f = Fruit::banana;
    Fruit a = Fruit::apple;
    std::cout << (a < f);
}

事实上,图像没有输入。 当我打印scope.post时,控制台上会打印一个空白对象。 我已经阅读了有关该主题的几个答案,但是没有任何关于如何在本地系统文件夹上传图像的问题。

1 个答案:

答案 0 :(得分:1)

尝试使用ngf-select,如下所示:

<强> HTML

<div ng-controller="MyCtrl">
   <input type="file" ngf-select="onFileSelect($files)" multiple>
</div>

<强>控制器

angular.module('myApp', ['ngFileUpload']);

var MyCtrl = ['$scope', 'Upload', function($scope, Upload) {
    $scope.onFileSelect = function($files) {
       for (var i = 0; i < $files.length; i++) {
          var $file = $files[i];
             Upload.upload({
             url: 'my/upload/url',
             file: $file,
          })
       }
     }
  }];

以下是jsFiddle

希望它有效:)

相关问题