首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >利用Angular6中的变量动态生成打印任务的超文本标记语言

利用Angular6中的变量动态生成打印任务的超文本标记语言
EN

Stack Overflow用户
提问于 2018-08-05 20:43:07
回答 1查看 36关注 0票数 0

当我运行这段代码时,我得到的不是值,而是对象名。

export class PrescriberComponent implements OnInit {
constructor() { }

people = [
    {id: 1, forename: 'John', surname: 'Doe'},
    {id: 2, forename: 'John', surname: 'Smith'},
    {id: 3, forename: 'Peter', surname: 'Scott'},
    {id: 4, forename: 'Sue', surname: 'Reece'}
];

PrintDoc1() : void {  
    var originalContents = ` 
    <table border="3" width="50%" cellpadding="2" cellspacing="3">
    <tr>
        <th colspan="2">
            <h2>table title</h2>
        </th>
    </tr>
    <tr>
        <th>First Name</th>
    </tr>
    <tr *ngFor="person in this.people">
        <td>{{person.forename}}</td>
    </tr>
    </table>
    `;  
    console.log(originalContents);
     var popupWin = window.open('', '_blank', 'width=600,height=600,scrollbars=no,menubar=no,toolbar=no,location=center,status=no,titlebar=no');
     popupWin.window.focus();
     popupWin.document.write('<!DOCTYPE html><html><head>' +
         '<link rel="stylesheet" type="text/css" href="style.css" />' +
         '</head><body onload="window.print()"><div class="reward-body">' + originalContents + '</div></html>');
    popupWin.document.close();
}

}



<button type="button" style="color: #ffffff;background-color: #28afde" (click)="PrintDoc1()">PRINT</button>

在输出中,我们只能看到对象名而不是值。我怀疑*ngFor和插值不是以这种方式工作的。

EN

回答 1

Stack Overflow用户

发布于 2018-08-05 21:53:24

尝试使用ngFor,如下所示,并尝试它

<li *ngFor="let person of people">
  {{ person.forename}}
</li>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51694421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档