Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs &引用;上传者“;必须是FileUploader的实例_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs &引用;上传者“;必须是FileUploader的实例

Angularjs &引用;上传者“;必须是FileUploader的实例,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我提到: angular.min.js:14540 TypeError:“Uploader”必须是FileUploader的实例 在链接(http://localhost:8080/services/angular-上传文件(js:1874:24) 在肯德基(http://localhost:8080/lib/js/angular.min.js:10445:8) 在诺德琳(http://localhost:8080/lib/js/angular.min.js:9733:9) 在KFN(http:

我提到:

angular.min.js:14540 TypeError:“Uploader”必须是FileUploader的实例
在链接(http://localhost:8080/services/angular-上传文件(js:1874:24)
在肯德基(http://localhost:8080/lib/js/angular.min.js:10445:8)
在诺德琳(http://localhost:8080/lib/js/angular.min.js:9733:9)
在KFN(http://localhost:8080/lib/js/angular.min.js:8712:10)
在KFN(http://localhost:8080/lib/js/angular.min.js:8717:10)
在KFN(http://localhost:8080/lib/js/angular.min.js:8717:10)
在KFN(http://localhost:8080/lib/js/angular.min.js:8717:10)
在KFN(http://localhost:8080/lib/js/angular.min.js:8717:10)
在publicLinkFn(http://localhost:8080/lib/js/angular.min.js:8567:9)
在链接(http://localhost:8080/lib/js/angular-路线:js:1053:5)
试试这个

<element ng-if="uploader">
    <input type="file" nv-file-select uploader="uploader" multiple />
</element>


我在angular file upload v2.3.4上进行了测试,效果很好

文件上传器应该在控制器全局范围内,以便创建与文件上传器相应的对象。我创建了一个工厂,并在整个控制器中使用它。

这是js部分,这是我在其中编写的服务,您可以传递FileUploader对象和url以及$scope变量

tmsApp.service("fileServices", function($http) {

    this.uploadFile = function(FileUploader, $scope, url) {
        var uploader = $scope.uploader = new FileUploader({
            url : url,
        });
        // FILTERS
        uploader.filters.push({
            name : 'customFilter',
            fn : function(item, options) {
                return this.queue.length < 10;
            }
        })
    }

})

我之所以会出现这个错误,是因为在我决定使用这个库之前,我在底部定义了另一个$scope.uploader方法,并且忘记了它


在注意到之前先尝试了其他的一切,最好的xD

你在哪里实例化上传程序…你需要在控制器中进行实例化。你当时是否尝试调试…我的意思是实例正在调试中,但实例没有创建。你能提供实例所在的代码吗?是的,你的解决方案很好,但我有不同的解决方案问题当我在整个控制器中使用时,它应该在全局范围内。@Deepanjan谢谢提示。我不得不把它放在$scope上,它解决了这个问题。我可以分享你的源代码吗?如何保存你的文件上传???我在同一个问题上叠加谢谢你想要哪个部分?保存或上传您使用的是哪种技术前端和后端?我使用angularjsi希望看到前端和后端,如果有机会的话。感谢您的回复,我很抱歉回复太晚。我的前端使用angularjs,后端使用ruby on rails,我有一个叫做纸夹的gem,当我使用angularjs文件上传器,上传器在我的纸夹中抛出空白数据,我不明白文件上传器是如何工作的,如果你能给我一个代码笔或JSFIDLE,我会很高兴,这样我就能理解更多的感谢你的帮助
tmsApp.service("fileServices", function($http) {

    this.uploadFile = function(FileUploader, $scope, url) {
        var uploader = $scope.uploader = new FileUploader({
            url : url,
        });
        // FILTERS
        uploader.filters.push({
            name : 'customFilter',
            fn : function(item, options) {
                return this.queue.length < 10;
            }
        })
    }

})
/**
 * 
 * @param file
 * @param projectId
 * @param taskId
 * @comments
 */
public void fileUpload(MultipartFile file, Long projectId, String taskId) {
    if (!file.isEmpty()) {
        try {
            String uploadsDir = location + "/uploads/" + "tenant/"
                    + authUtilService.getLoggedInUsersTenantName()
                    + "/project/" + projectId + "/task/" + taskId + "/";

            if (!new File(uploadsDir).exists()) {
                new File(uploadsDir).mkdirs();
                log.info("Directory Created");
            }
            log.info("realPathtoUploads = {}", uploadsDir);
            String originalFileName = file.getOriginalFilename();
            String filePath = uploadsDir + originalFileName;
            File destination = new File(filePath);
            file.transferTo(destination);

            Task task = taskRepository.findByIdAndTenant(taskId,
                    authUtilService.getLoggedInUsersTenant());
            taskHistoryService.addAuditUtility(TaskAudit.FILE, task,
                    originalFileName);

        } catch (Exception e) {
        }

    } else {
        log.info("File upload Failed!! Try again.....");
    }
}