Angular can’t use await in TypeScript function

I am using Angular and in a function to generate two DIVs to 2 pages PDF I am using await but it’s not working and giving me this error 'await' expressions are only allowed within async functions and at the top levels of modules.

const pdf = new jsPDF('p', 'mm', 'a4');
const imgWidth = 208;
const position = 0;

let data = document.getElementById('pdf-one')!;
let dataTwo = document.getElementById('pdf-two')!;
const [imgPage1, imgPage2] = await Promise.all([html2canvas(data), html2canvas(dataTwo)]);
// Process first image
let imgHeight = imgPage1.height * imgWidth / imgPage1.width;
let contentDataURL = imgPage1.toDataURL('image/jpeg');
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
pdf.addPage();
// Process second image
imgHeight = imgPage2.height * imgWidth / imgPage2.width;
contentDataURL = imgPage2.toDataURL('image/jpeg');
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);

pdf.save('Result.pdf');