本文整理汇总了TypeScript中angular.element.param方法的典型用法代码示例。如果您正苦于以下问题:TypeScript element.param方法的具体用法?TypeScript element.param怎么用?TypeScript element.param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular.element
的用法示例。
在下文中一共展示了element.param方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: XMLHttpRequest
return this.$q((resolve: () => void) => {
if (typeof (Blob) !== 'undefined') {
// post request for download the file
const xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.responseType = 'arraybuffer';
const selfXhr = xhr;
xhr.onload = (evt) => {
console.log('downloadFileRequest xhr.onload evt: ', evt);
if (selfXhr.status !== 200)
return;
const disposition = xhr.getResponseHeader('Content-Disposition');
let filename = '';
if (disposition && disposition.toLowerCase().indexOf('attachment') !== -1) {
const filenameRegex = /[Ff]ilename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
const matches = filenameRegex.exec(disposition);
if (matches != null && matches[1])
filename = matches[1].replace(/['"]/g, '');
}
const type = xhr.getResponseHeader('Content-Type');
const blob = new Blob([selfXhr.response], { type: type });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created.
// These URLs will no longer resolve as the data backing the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
resolve();
} else {
const urlFunc = window.URL || window['webkitURL'];
var downloadUrl = urlFunc.createObjectURL(blob);
if (filename) {
// use HTML5 a[download] attribute to specify filename
const linkElement = document.createElement('a');
// safari doesn't support this yet
if (typeof linkElement.download === 'undefined') {
window.location.href = downloadUrl;
} else {
linkElement.href = downloadUrl;
linkElement.target = '_blank';
linkElement.download = filename;
document.body.appendChild(linkElement);
linkElement.click();
document.body.removeChild(linkElement);
}
} else {
window.location.href = downloadUrl;
}
setTimeout(() => {
urlFunc.revokeObjectURL(downloadUrl);
resolve();
}, 100); // cleanup
}
};
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
if (method.toLowerCase() === 'post')
xhr.send(angular.element.param(parameters || {}));
else if (method.toLowerCase() === 'get')
xhr.send();
else
throw `Unsupported request method: ${method}`;
} else {
if (method.toLowerCase() === 'post') {
// old browser post request
const form = document.createElement('form');
form.action = url;
form.method = method;
form.target = '_blank';
if (parameters)
for (let key in parameters)
if (parameters.hasOwnProperty(key)) {
const input = document.createElement('textarea');
input.name = key;
input.value = typeof parameters[key] === 'object' ? JSON.stringify(parameters[key]) : parameters[key];
form.appendChild(input);
}
form.style.display = 'none';
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
} else {
// old browser get request
const linkElement2 = document.createElement('a');
linkElement2.href = url;
linkElement2.target = '_blank';
document.body.appendChild(linkElement2);
linkElement2.click();
document.body.removeChild(linkElement2);
}
resolve();
}
});