Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 http post在文件上载标记中不起作用_Http_Angularjs_File Upload_Http Post_Multipartform Data - Fatal编程技术网

angularjs http post在文件上载标记中不起作用

angularjs http post在文件上载标记中不起作用,http,angularjs,file-upload,http-post,multipartform-data,Http,Angularjs,File Upload,Http Post,Multipartform Data,在angularjs中上载文件不起作用。我在浏览器中未找到任何发送到后端的请求,在调试模式下,我同时在浏览器和后端中检查: <div> <input type="file" accept="text/plain" name="tandcproduct" onchange="angular.element(this).scope().uploadTerms(this.files)" ng-required/> </div> 我做错了什么?如果你

在angularjs中上载文件不起作用。我在浏览器中未找到任何发送到后端的请求,在调试模式下,我同时在浏览器和后端中检查:

<div>
    <input type="file" accept="text/plain" name="tandcproduct"
    onchange="angular.element(this).scope().uploadTerms(this.files)" ng-required/>
</div>

我做错了什么?

如果你先看一些,你会找到答案。@Studie,我过去处理过很多http post请求。。相同的代码将在文件上传方法之外工作,但在其中不工作?明白了吗?onchange属性的内联使用在大约10年前就被弃用了。使用angular.element访问scope方法this.scope完全是对所有angular实践的滥用。同样,我建议您阅读文档、教程和docs for ng change指令。在文档中:如果请求配置对象的数据属性包含一个对象,请将其序列化为JSON格式。ng click=uploadTerms事件将在上述上下文中触发。但是如果没有angular.element this.scope.uploadTermsthis.files,则该文件不起作用。在任何其他方法中,post对象都起作用
 $scope.uploadTerms = function(files) {
    fd.append("file", files[0]);
        $http({
            method:'POST',
            url: ctxPath+'fileupload/productconfig',
            headers: {
            'Content-Type': 'multipart/form-data'
            },
            data: fd
            }).
            then(function(result) {
            alert(result);
            });
    }