Kam*_*dos 3 device-detection angular-universal angular
我正在使用ngx-device- detector库来检测设备类型(移动设备、平板电脑或台式机)。该库在客户端模式下完美工作,但当角度通用应用程序在服务器上预渲染时无法检测设备类型(在服务器上预渲染后,在客户端模式下完美工作)。
谢谢。
我快速浏览了代码,我认为您可以setDeviceInfo使用可以从请求标头中检索的用户代理字符串进行调用
应用程序模块.ts
import {Request} from 'express';
import {REQUEST} from '@nguniversal/express-engine/tokens';
constructor(@Inject(PLATFORM_ID) private platformId,
@Optional() @Inject(REQUEST) protected request: Request,
private deviceService: DeviceDetectorService)
{
if(!isPlatformBrowser(platformId))
{
this.deviceService.setDeviceInfo(request.headers['user-agent']);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4603 次 |
| 最近记录: |