小编Kir*_*bel的帖子

我不能在 Angular 10 中使用 jsPDF

我试图使用jspdf库打印我的页面。我已经尝试了很多解决方案来完成这里的示例和几乎每个谷歌建议链接,但我仍然无法修复它。

这是我迄今为止尝试过的:

import * as jsPDF from 'jspdf';
.....
openPDF(): void {
    const DATA = this.couponPage.nativeElement;
    const doc = new jsPDF('p', 'pt', 'a4');
    doc.fromHTML(DATA.innerHTML, 15, 15);
    doc.output('dataurlnewwindow');
}
Run Code Online (Sandbox Code Playgroud)

尝试jsPDF像上面那样导入会在编译时产生以下错误

src/...component.ts:42:21 中的错误 - 错误 TS2351:此表达式不可构造。类型 'typeof import("jspdf")' 没有构造签名。

42     const doc = new jsPDF('p', 'pt', 'a4');
Run Code Online (Sandbox Code Playgroud)

因此,我尝试按照此stackoverflow 答案中的建议以另一种方式导入它

declare var jsPDF: any;
Run Code Online (Sandbox Code Playgroud)

然而,这会产生一个控制台错误,指出jsPDF未定义。

然后我找到了另一个解决方案,如此处发布的Angular 10/9/8 PDF Tutorial – Export PDF in Angular with JSPDF

现在按照这个方法我得到了以下错误

错误类型错误:doc.fromHTML 不是函数 openPDF notice.component.ts:43 ...Component_Template_button_click_2_listener ...component.html:3 Angular …

jspdf angular

8
推荐指数
1
解决办法
7006
查看次数

使用变量进行 Flutter 本地化

我正在尝试按照文档本地化我的 Flutter 应用程序。

我想要实现的是,在动态构建小部件时,我想翻译来自我的模型的数据。这是我到目前为止所尝试过的

List.generate(services.length, (index) {
  final Service service = services[index];
  return Material(
    borderRadius: BorderRadius.circular(10.0),
    child: Text(
      AppLocalizations.of(context).{{service.title}} // Here I wanted to translate the service title
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在 Flutter 中实现这一目标?或任何其他可能的方法来翻译动态内容。

dart flutter

6
推荐指数
1
解决办法
3748
查看次数

如何将 id 绑定到 PrimeNg 菜单命令

我有一张桌子,上面列出了物品清单。我想使用 PrimeNg Menu 作为下拉菜单选项来导航到具有所选项目 ID 的其他页面。我想做的是,当我单击菜单项时,我想绑定所选项目的 id。

我的 HTML 看起来像这样

<tr *ngFor="let item of items" class="animated fadeIn">
    <td>{{item.category}}</td>
    <td>{{item.name}}</td>
    <td>{{item.date}}</td>
    <td>
       <div>
           <p-menu #tableMenu [popup]="true" [model]="tableMenuItems" appendTo="body"></p-menu>
               <button type="button" pButton icon="pi pi-ellipsis-v"
                   class="ui-button-secondary ui-button-rounded ui-button-transparent"
                   (click)="tableMenu.toggle($event)">
               </button>
       </div>
    </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

和我的.ts

this.tableMenuItems = [
  {
    label: 'View Item', command: (event) => {
      // this.viewItemDetail() // here I wanted to bind item.id of the selected item and navigate to item detail page
    }
  },
  {
    label: 'Edit Item', command: (event) => …
Run Code Online (Sandbox Code Playgroud)

javascript typescript primeng angular

4
推荐指数
1
解决办法
3535
查看次数

标签 统计

angular ×2

dart ×1

flutter ×1

javascript ×1

jspdf ×1

primeng ×1

typescript ×1