更新后无法使用Angular Universal注入文档

发布时间:2020-07-06 15:19

我们正在使用Angular Universal进行服务器端渲染。从Angular 8升级到10之后,服务中出现运行时错误,从而注入了文档抽象:

export class FooService {
^
ReferenceError: Document is not defined

代码:

import { DOCUMENT } from '@angular/common';
...
@Injectable({
   providedIn: 'root'
})
export class FooService {
...

constructor(@Inject(DOCUMENT) private document: Document) { ... }

如何像以前在Angular 8中一样正确地注入文档抽象?

更新:这是我的tsconfig.server.json:

{
  "extends": "./tsconfig.app.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app-server",
    "baseUrl": ".",
    "target": "es2016",
    "types": [
      "node"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "entryModule": "app/app.server.module#AppServerModule"
  }
}
回答1