[英]How to Render an Angular Component to HTML in Node.Js (To Send EMails)
[英]Get angular component generated HTML by node.js
这是一个体系结构\\设计\\最佳实践问题:我有一个基于angular2 +的应用程序,其中所有应用程序都将渲染的HTML(使用html元素引用的ElementElement.outerHTML-ElementRef)发送到服务器,并作为响应接收HttpResponseMessage 。 我想以异步方式进行操作,即将其作为计划任务运行。 我想使用node.js做到这一点。 node.js具有向html文件发出请求的选项。 问题是由于角度路由系统的缘故,我仅通过提供url就无法获得html生成的页面。 是否还有其他选择\\想法?
您可以使用@ViewChild
装饰器,然后可以使用具有@ViewChild
属性的HTML。 例如:
app.component.html:
<div #someHTML>
<h1>Hello world</h1>
</div>
<button (click)="test()" >Test</button>
app.component.ts:
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
@ViewChild('someHTML') someHTML: ElementRef;
test(){
console.log(this.someHTML.nativeElement.outerHTML)
}
}
现在,您可以使用html将请求发送到服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.