【问题标题】:How to preload files blueimp jquery-file-upload angular version?如何预加载文件 blueimp jquery-file-upload 角度版本?
【发布时间】:2017-12-15 20:28:06
【问题描述】:

当尝试加载之前从服务器上传的文件时,会产生以下错误。

// Load existing files:
$.ajax({
    url: $('#fileupload').fileupload('option', 'url'),
    dataType: 'json',
    context: $('#fileupload')[0]
}).done(function (result) {
    $(this).fileupload('option', 'done').call(this, $.Event('done'), {result: files});
});

//Exception
jquery.fileupload-angular.js:130 Uncaught TypeError: Cannot read property '$apply' of undefined
    at done (jquery.fileupload-angular.js:130)
    at <anonymous>:2:47

下面的 sn-p 在FileUploadController 中,它将$scope 放入文件数据中。

$element.fileupload(angular.extend(
  {scope: $scope},
  fileUpload.defaults
)).on('fileuploadadd', function (e, data) {
    data.scope = $scope;

【问题讨论】:

    标签: jquery angularjs jquery-file-upload blueimp


    【解决方案1】:

    所以一个解决方案“hacky”是为指令注入一个服务到控制器中并调用generateFileObject(files)方法。

    .directive('ngUploadForm', [function () {
      return {
        restrict: 'E',
        templateUrl: 'templates/uploadform.html',
        scope: {
          allowed: '@',
          url: '@',
          autoUpload: '@',
          sizeLimit: '@',
          ngModel: '=',
          name: '@'
        },
        controller: ['$scope', '$element', 'fileUpload','FileService', function ($scope, $element, fileUpload, FileService)
    
    [other code]
    
    // pre-populate file list
    FileService.getSavedFiles()
      .done(function(files){
        generateFileObject(files)
      });
    

    文件服务代码(基本 jquery ajax)

    this.getSavedFiles = function(){
        return $.ajax({
          url: this.getFileUrl(),
          dataType: 'json'
        });
    

    【讨论】:

      猜你喜欢
      • 2017-08-13
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多