0
クリック時に値を変更してクリックに反映させるにはどうすればよいですか?クリックで値を変更する方法は?
@Component({
selector: 'my-app',
template: `
<div>
<div id="print-section">
Test print {{ name }}
</div>
<button (click)="print()">print</button>
</div>
`,
})
export class App {
name:string;
name="Red";
constructor() {
}
print(): void {
let printContents, popupWin;
this.name="Blue";
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=700,width=1000');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<title>Print tab</title>
<style>
//........Customized style.......
</style>
</head>
<body onload="window.print();window.close()">${printContents}</body>
</html>`
);
popupWin.document.close();
}
}
ここで私はname = "Red"と宣言しました。印刷をクリックした後、青色になります。しかし、それは最初のクリックで同じです。
https://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5?p=preview
私のテストしていません。ボタンをクリックすると、テキストが青色に変わります。 https://plnkr.co/edit/iiAJA01moYpbISojkLeT?p=preview –