获取Angular Universal中的主机名和路径名信息
发布时间:2020-12-17 17:28:42 所属栏目:安全 来源:网络整理
导读:有没有人知道如何在Angular universal中访问主机名和路径名信息? 在客户端应用程序中,您可以访问具有该信息的窗口对象. 我只需要服务器上的那些信息? 解决方法 随着 ngExpressEngine: server.ts: ...app.engine('html',(_,options,callback) = { let eng
有没有人知道如何在Angular universal中访问主机名和路径名信息?
在客户端应用程序中,您可以访问具有该信息的窗口对象. 我只需要服务器上的那些信息? 解决方法
随着
ngExpressEngine:
server.ts: ... app.engine('html',(_,options,callback) => { let engine = ngExpressEngine({ bootstrap: ServerAppModule,providers: [ { provide: 'host',useFactory: () => options.req.get('host') } ] }); engine(_,callback) }) ... app.component.ts: import { Inject,Injector,PLATFORM_ID } from '@angular/core'; import { DOCUMENT,isPlatformServer } from '@angular/common'; ... constructor(@Inject(DOCUMENT) private document,private injector: Injector,@Inject(PLATFORM_ID) private platformId: Object) { if (isPlatformServer(this.platformId)) { console.log(this.injector.get('host')) } else { console.log('document: ',document.location.hostname); } } 没有ngExpressEngine: server.ts: ... app.engine('html',callback) => { const opts = { document: template,url: options.req.url,extraProviders: [{ provide: 'host',useFactory: () => options.req.get('host') }] }; renderModuleFactory(AppServerModuleNgFactory,opts) .then(html => callback(null,html)); }); ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- iis-7 – 为AngularJS配置IIS URL重写模块HTML5Mode仍无效
- webservice入门(操作篇)
- nginx配置upstream实现负载均衡
- Shell case esac 语句
- scala – Lift – Page在Firefox中显示为XML而不是HTML
- angular6 – 错误:rxjs / operator / map没有导出成员’ma
- CXF WebService整合Spring
- typescript – Angular2 rxjs缺少observable.interval方法
- twitter-bootstrap – 是否有任何维护良好且及时更新的指南
- Twitter Bootstrap 框架介绍