'Cannot read properties of undefined (reading 'forEach')
Issue The first issue it says jspdf is not a constructor, and now it comes unable to read of undefine for each any idea what is causing this issue,I'm using jspdf 2.5.1 latest package.json this is my package.json file is there any to upgrade or downgrade the version
{
"name": "healthcare-frontend-angular",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build-prod": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng build --configuration production"
},
"private": true,
"dependencies": {
"@angular-devkit/build-webpack": "~0.1202.17",
"@angular/animations": "^12.2.16",
"@angular/cdk": "12.2.13",
"@angular/common": "^12.2.16",
"@angular/compiler": "^12.2.16",
"@angular/core": "^12.2.16",
"@angular/elements": "^12.2.16",
"@angular/forms": "^12.2.16",
"@angular/material": "^12.2.13",
"@angular/platform-browser": "^12.2.16",
"@angular/platform-browser-dynamic": "^12.2.16",
"@angular/router": "^12.2.16",
"@aspnet/signalr": "^1.0.3",
"@kolkov/angular-editor": "^1.2.0",
"@ng-idle/core": "^8.0.0-beta.4",
"@ng-idle/keepalive": "^8.0.0-beta.4",
"@opentok/client": "^2.15.5",
"angular-calendar": "^0.28.26",
"angular-chat-awesome": "^1.0.1",
"angular-font-awesome": "^3.1.2",
"angular-formio": "^4.11.5",
"angular-notifier": "^4.1.1",
"angular2-signaturepad": "^3.0.4",
"base-64": "^0.1.0",
"bootstrap": "^4.5.0",
"chart.js": "^2.9.4",
"classlist.js": "^1.1.20150312",
"core-js": "^2.6.11",
"crypto-js": "^3.1.9-1",
"css-loader": "^6.7.1",
"date-fns": "^1.29.0",
"google-libphonenumber": "^3.2.2",
"hammerjs": "^2.0.8",
"jspdf": "^2.5.1",
"jspdf-autotable": "^3.5.23",
"moment-timezone": "^0.5.23",
"ng2-charts": "^2.4.3",
"ngx-color-picker": "^6.7.0",
"ngx-google-places-autocomplete": "^2.0.3",
"ngx-intl-tel-input": "^2.1.0",
"ngx-mask": "^6.5.18",
"ngx-mat-select-search": "^3.3.0",
"ngx-material-timepicker": "^2.13.0",
"ngx-quill": "^4.4.5",
"ngx-scrollbar": "^7.6.1",
"rxjs": "^6.6.7",
"sass": "^1.50.0",
"tslib": "^2.4.0",
"utf8": "^3.0.0",
"web-animations-js": "^2.3.2",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.2.17",
"@angular/cli": "^12.2.17",
"@angular/compiler-cli": "^12.2.16",
"@angular/language-service": "^12.2.16",
"@types/hammerjs": "^2.0.41",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.17",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"sass-loader": "^7.1.0",
"ts-node": "~7.0.0",
"tslint": "~6.1.0",
"typescript": "~4.3.5"
}
}
code errors occurs in this section at this.prescriptionModel.prescriptionDetails.forEach i have no idea what is causing this issue. Am i missing any. Or is it related to any version issue
downloadPDF(isSubmit:any) {
let doc = new jsPDF();
let rows: Array<any> = [];
let medicineInfo: any;
let physicianInfo: any;
doc.page = 1;
var col = ["Medicine Name", "Dose", "Dispense"];
this.prescriptionModel.prescriptionDetails.forEach((a) => {
medicineInfo = this.masterDrugMedication.find(x => x.id == a.prescriptionId);
rows.push(['' + medicineInfo.productName + ' ' + a.strength + ', ' + medicineInfo.route + '', '' + a.direction + '', '' + a.quantity + '']);
});
physicianInfo = this.masterStaff.find(x => x.id == this.prescriptionModel.physician);
if (this.prescriptionModel.id > 0) {
if (this.reportCommonData != null) {
doc.setProperties({title: "Prescription Report"});
doc.setFontType("bold");
doc.setFontSize(16);
doc.text(15, 20, "Prescription Report");
doc.setFontSize(10);
doc.setFontType("bold");
doc.text(140, 20, "Provider Details:");
doc.setFontType("normal");
doc.text(140, 25, "Name: " + this.reportCommonData.organizationName);
doc.text(140, 30, "Address: " + this.reportCommonData.address);
doc.text(140, 35, "Phone: " + this.reportCommonData.phone);
doc.text(140, 40, "Email: " + this.reportCommonData.email);
doc.setFontType("bold");
doc.text(15, 35, "Patient Details:");
doc.setFontType("normal");
doc.text(15, 40, "Name: " + this.reportCommonData.firstName + " " + this.reportCommonData.lastName);
doc.text(15, 45, "MRN: " + this.reportCommonData.patientMRN);
doc.text(15, 50, "Email: " + this.reportCommonData.patientEmail);
doc.text(15, 55, "Phone: " + this.reportCommonData.patientPhone);
doc.setFontType("bold");
doc.text(140, 50, "Physician Details:");
doc.setFontType("normal");
doc.text(140, 55, "Name: " + physicianInfo.firstName + " " + physicianInfo.lastName);
doc.text(140, 60, "NPI Number: " + physicianInfo.npiNumber);
doc.text(140, 65, "Phone: " + physicianInfo.phoneNumber);
doc.setFontType("bold");
doc.text(15, 65, 'Pharmacy Details:');
doc.setFontType("normal");
doc.text(15, 70, "Name: " + this.PharmacyInfo.pharmacyName);
doc.text(15, 75, "Address: " + this.PharmacyInfo.address1);
doc.text(15, 80, "City: " + this.PharmacyInfo.city);
doc.text(15, 85, "Email: " + this.PharmacyInfo.email);
doc.text(15, 90, "Phone:" + this.PharmacyInfo.phone);
doc.text(15, 95, "Prescription Date: " + this.datePipe.transform(this.prescriptionModel.createdDate, 'M/d/yyyy, h:mm a'));
doc.autoTable({
columnStyles: {
0: { cellWidth: 120 },
1: { cellWidth: 40 },
2: { cellWidth: 20 }
},
head: [col],
body: rows,
startY: 100,
theme: 'plain',
tableLineColor: [242, 238, 238],
tableLineWidth: 0.5,
styles: {
font: 'courier',
lineColor: [242, 238, 238],
lineWidth: 0.5
},
});
doc.setFontType("bold");
doc.setFontSize(7);
doc.text(15,260, "Disclaimer");
doc.setFontType("normal");
doc.text(15,265, "Eveda (“the Agency”) makes the information and other material (“Information”) in this document available in good faith but without any representation or warranty");
doc.text(15,270, "as to its accuracy or completeness. The Agency cannot accept any responsibility for the consequences of any use of the Information. As the Information is of ");
doc.text(15,275, "a general nature only, it is up to any person using or relying on the Information to ensure that it is accurate, complete and suitable for the circumstances of its use.");
doc.setFontType("bold");
doc.text(65,280,"This is a computer-generated document. No signature is required");
doc.setFontSize(5);
doc.setFontType("normal");
doc.text(180, 285,'Powered by Eveda AUSNZ Pty Ltd');
if(!isSubmit){
window.open(doc.output('bloburl'))
}else{
this.fileList.push({
data: doc.output('datauristring'),
ext: 'pdf'
});
}
}
}
}
Solution 1:[1]
You haven't provided enough code to be able to help, consider providing us with a minimal reproducible example. Anyways, I'm going to try the best to help you: this.prescriptionModel obviously is not undefined, so for some reason, this.prescriptionModel.prescriptionDetails is undefined.
P. s.: I will make sure to update my answer as soon as more details are provided, but currently, not enough of the code is provided to be able to provide a helpful answer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TopchetoEU |
