admin管理员组文章数量:1434381
I'm trying to create PDF from data input in an Angular 2 project. To do this, I integrated pdfMake. Creating static PDF works just fine, but the moment I try to print out some values, it goes wrong.
Please have a look at this plunker:
I manage to put an object into my buildPdf function and it gets loged to the console. But when I try to add one of my object values to the pdfMake docdefinition, I'm getting the error message:
ORIGINAL EXCEPTION: TypeError: Cannot read property 'firstName' of undefined
var docDefinition = {
content: [{
text: 'My name is: ' + pdfContent.firstName + ' ' + pdfContent.lastName + '.'
}]
}
I tried to rule out a typing issue by rewriting my buildPdf.js in typescript, which looked something like this:
var buildPdf: (value: {firstName: string, lastName: string}) => any =
function(value: {firstName: string, lastName: string}): any {
let docDefinition:any = {
content: [{
text: 'This is a test.'
}]
}
console.log(value);
return docDefinition;
}
The result stayed the same, though.
Why am I able to console.log the object but not to access its properties? What have I missed?
I'm trying to create PDF from data input in an Angular 2 project. To do this, I integrated pdfMake. Creating static PDF works just fine, but the moment I try to print out some values, it goes wrong.
Please have a look at this plunker: https://plnkr.co/edit/7tPFTAjKWwaRp1IbT0Tg?p=preview
I manage to put an object into my buildPdf function and it gets loged to the console. But when I try to add one of my object values to the pdfMake docdefinition, I'm getting the error message:
ORIGINAL EXCEPTION: TypeError: Cannot read property 'firstName' of undefined
var docDefinition = {
content: [{
text: 'My name is: ' + pdfContent.firstName + ' ' + pdfContent.lastName + '.'
}]
}
I tried to rule out a typing issue by rewriting my buildPdf.js in typescript, which looked something like this:
var buildPdf: (value: {firstName: string, lastName: string}) => any =
function(value: {firstName: string, lastName: string}): any {
let docDefinition:any = {
content: [{
text: 'This is a test.'
}]
}
console.log(value);
return docDefinition;
}
The result stayed the same, though.
Why am I able to console.log the object but not to access its properties? What have I missed?
Share Improve this question edited Mar 1, 2016 at 10:23 Günter Zöchbauer 659k234 gold badges2.1k silver badges1.6k bronze badges asked Mar 1, 2016 at 10:19 mgogamgoga 331 silver badge4 bronze badges1 Answer
Reset to default 4Seems to be caused by this line
buildPdf: any = new buildPdf();
I don't see what you need it for. It throws because it accesses the passed value but here none is passed.
See https://plnkr.co/edit/NPLHxVgC5LthA4g2WpUx?p=preview for the working Plunker.
本文标签: javascriptUse pdfMake with data input in Angular 2TypeScriptStack Overflow
版权声明:本文标题:javascript - Use pdfMake with data input in Angular 2TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745624779a2666906.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论