在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ Angular4 服務(wù)端渲染報(bào)錯(cuò)

Angular4 服務(wù)端渲染報(bào)錯(cuò)

這是一個(gè)angular4的項(xiàng)目,使用了服務(wù)端渲染,在引入了一個(gè)第三方的富文本編輯器——wangeditor后,出現(xiàn)了如下問題

 _ua: navigator.userAgent,
         ^

ReferenceError: navigator is not defined

一般遇到這種不支持服務(wù)端渲染的部分,我都是使用官方推薦的方法,判斷當(dāng)前平臺(tái),然后決定是否執(zhí)行,如下:

import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
 
constructor(@Inject(PLATFORM_ID) private platformId: Object) { ... }
 
ngOnInit() {
  if (isPlatformBrowser(this.platformId)) {
     // Client only code.
     ...
  }
  if (isPlatformServer(this.platformId)) {
    // Server only code.
    ...
  }
}

但是這個(gè)方法對(duì)這個(gè)編輯器似乎沒有啥作用,即時(shí)被旁路了,跑服務(wù)端渲染的時(shí)候也還是依舊報(bào)錯(cuò),有沒有大神能幫忙分析一下啥原因。。。謝謝各位??!

回答
編輯回答
晚風(fēng)眠

主模塊里引入 BrowserModule 試試

2017年3月27日 19:13