Javascript 如何处理$broadcast以使用ajax加载spinner和文件上载
我正在使用我在中找到的一些代码: 为了满足我的需要,它做了一些轻微的修改,但基本上做了相同的事情 由于浏览器的支持,我有一个表单提交到iframe来上传文件,我不能使用AJAX。在开始上载之前,我使用以下代码打开加载微调器:Javascript 如何处理$broadcast以使用ajax加载spinner和文件上载,javascript,angularjs,Javascript,Angularjs,我正在使用我在中找到的一些代码: 为了满足我的需要,它做了一些轻微的修改,但基本上做了相同的事情 由于浏览器的支持,我有一个表单提交到iframe来上传文件,我不能使用AJAX。在开始上载之前,我使用以下代码打开加载微调器: $rootScope.$broadcast('loader_show'); 类似地,将此代码与“loader\u hide”一起使用来隐藏微调器 问题在于,在上载一个大的~20MB文件的过程中,keep-alive AJAX调用会关闭微调器,因为numload部分在文件上
$rootScope.$broadcast('loader_show');
类似地,将此代码与“loader\u hide”一起使用来隐藏微调器
问题在于,在上载一个大的~20MB文件的过程中,keep-alive AJAX调用会关闭微调器,因为numload部分在文件上载过程中不会增加/减少。有没有办法在提交表单的控制器中访问httpInterceptor来处理这个问题?由于对AngularJS缺乏经验,我没有意识到httpInterceptor在本例中只是一个连接到$httpProvider作为拦截器的服务。一旦我掌握了这个概念,就很容易了 在提交表单的控制器中,只需像这样连接服务并调用请求: 在从iframe响应调用的回调中:
function processFileUpload(data) {
// do stuff to handle returned data, and then...
angular.element('#configFileUploadForm')
.injector().get('httpInterceptor').response(); // turns off spinner
}
希望这对其他人有帮助
.controller('ConfigurationUploadFileCtrl', function($scope, httpInterceptor) {
// this is called with ng-click on a button
$scope.processForm = function(form) {
httpInterceptor.request(); // turns on spinner
// do stuff to submit the form...
};
}
function processFileUpload(data) {
// do stuff to handle returned data, and then...
angular.element('#configFileUploadForm')
.injector().get('httpInterceptor').response(); // turns off spinner
}