0
我想从服务器端使用角度2应用程序通过发送HTML内容到服务器使用ElementRef创建PDF但它只发送HTML部分不是角度绑定part.I还想在我的HTML内容中添加CSS部分。因此,我想知道ElementRef是最好的方法,或者我应该尝试其他任何方法。发送Html内容到服务器创建PDF Angular 2
Component.ts
import { AfterContentInit, Component, ElementRef } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<table>
<thead>
<tr>
<th>username</th>
<th>email</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of data">
<td>{{ data.username }}</td>
<td>{{ data.email }}</td>
<td>{{ data.first_name }}</td>
</tr>
</tbody>
</table>`
})
export class AppComponent implements AfterContentInit {
node: string;
data = [
{
"id": 11,
"username": "abc",
"email": "[email protected]",
"first_name": "ramesh"
},
{
"id": 13,
"username": "btest",
"email": "[email protected]",
"first_name": "btest"
},
{
"id": 14,
"username": "abcd",
"email": "[email protected]",
"first_name": "abcd"
},
{
"id": 15,
"username": "demotest",
"email": "[email protected]",
"first_name": "demotest",
"last_name": "demo"
}
]
constructor(private elementRef: ElementRef) { }
ngAfterContentInit() {
this.node = this.elementRef.nativeElement.innerHTML;
}
}
只发送以下数据:
<table class="table table-striped">
<thead>
<tr>
<th>username</th>
<th>email</th>
<th>name</th>
</tr>
</thead>
<tbody>
<!--template bindings={}-->
</tbody>
</table>
而且我想给喜欢
<table class="table table-striped">
<thead>
<tr>
<th>username</th>
<th>email</th>
<th>name</th>
</tr>
</thead>
<tbody>
<!--template bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object],[object Object],[object Object]"
}--><tr>
<td>abc</td>
<td>[email protected]</td>
<td>ramesh</td>
</tr><tr>
<td>btest</td>
<td>[email protected]</td>
<td>btest</td>
</tr><tr>
<td>abcd</td>
<td>[email protected]</td>
<td>abcd</td>
</tr><tr>
<td>demotest</td>
<td>[email protected]</td>
<td>demotest</td>
</tr>
</tbody>
</table>
https://stackoverflow.com/a/778897/4099454 – Hitmands