Error after added ng-toolkit/universal - ERROR { Error: Uncaught (in promise): Error

Error after added ng-toolkit/universal - ERROR { Error: Uncaught (in promise): Error

我加了@ng-toolkit/universal

ng add @ng-toolkit/universal

我有一大堆错误,所以我正在构建备份添加的项目并一次测试每个 component/feature。大多数事情现在都在工作,但是,我似乎被困在一个问题上 -

我想在应用程序加载时预加载一些资产,所以我最初有这一行,它在 ng-toolkit/universal 之前完美运行 app.module.ts

providers: [WorkService, { provide: APP_INITIALIZER, useFactory: workProviderFactory, deps: [WorkService], multi: true }],

并且在 WorkService.service.ts

    import {Injectable} from '@angular/core';
    import {HttpClient, HttpResponse} from '@angular/common/http';
    import {Project} from '../models/work-model';
    import * as THREE from 'three';

    @Injectable()
    export class WorkService {
      private timeout = 10000;
      private errorMessages = {
        0: 'internet-error',
        500: 'server-error',
        timeout: 'timeout-error'
      };
      private data: Project[];
    private tileTextures: any = [];
      constructor(private http: HttpClient) {
      }

      getData(): any {
        return this.data;
      }


      load(): Promise<any> {
    let promise = new Promise((resolve, reject) => {
      this.http.get('/assets/case-studies/work.json')
        .toPromise()
        .then(
          res => {
            this.data = res['work'];
            resolve(true);
          },
          msg => {
            reject(msg);
          }
        )
         .catch((err) => console.log("rejected:", err));
    });
    return promise;
  }
}

但我收到以下错误 -

ERROR [Error]
[Error]
ERROR { Error: Uncaught (in promise): Error
    at resolvePromise (dist/server.js:200857:31)
    at resolvePromise (dist/server.js:200814:17)
    at dist/server.js:200916:17
    at ZoneDelegate.module.exports.ZoneDelegate.invokeTask (dist/server.js:200464:31)
    at Object.onInvokeTask (dist/server.js:4192:33)
    at ZoneDelegate.module.exports.ZoneDelegate.invokeTask (dist/server.js:200463:36)
    at Zone.module.exports.Zone.runTask (dist/server.js:200231:47)
    at drainMicroTaskQueue (dist/server.js:200638:35)
    at module.exports.ZoneTask.invokeTask (dist/server.js:200543:21)
    at Server.ZoneTask.invoke (dist/server.js:200528:48)
  rejection: [Error],
  promise: ZoneAwarePromise { __zone_symbol__state: 0, __zone_symbol__value: [Error] },

我认为如果您使用的是 Universal,则需要使用绝对路径,例如/assets/case-studies/work.json 在节点服务器上 运行 时将不起作用。看到这个 issue