I have a situation where the $http reponseType is dependent on url query parameter. When output-target=html and if I don't mention responseType at all, I am able to get the response in html properly. However when output-target=xls, I need to do this, to make it work and have responseType set to arraybuffer (to get response in excel)
var blob = new Blob([data], {type: "application/vnd.ms-excel"});
$http({
method: 'GET',
url: "https://xyz/abc?output-target=" + $scope.outputTarget,
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': '*/*'},
responseType: arraybuffer //for $scope.outputTarget=xls
})
I need something which will accept all kind of response types. If that option is not available, what is the way around?
I also tried passing function to responseType but that didn't work either.
responseType: (function () {
if($scope.outputTarget === "table/excel;page-mode=flow") {
var arraybuffer
return arraybuffer;
} else {return;}
})()