Angular4 Universal - xhr2.XMLHttpRequest不是构造函数

时间:2017-09-21 13:14:25

标签: angular xmlhttprequest angular-http angular-universal

我的通用项目存在问题:

我有以下服务:

public getData(): Observable<Article[]> {
    return this.getJson(this.relativeUrl).map(response => {
        const data = response.json();
        return data.map((item) => new Article().deserialize(item));
    })
        .catch(this.handleError);
}

我拨打以下电话:

private getArticles () {
    this.articleService
        .getData()
        .subscribe(
            (articles) => this.articles = articles,
            error => this.errorMessage = <any>error
        )
}

这在我正常的Angular项目中运行良好,但是如果我为Angular-Universal包含 ServerModule ,则会失败。有人知道问题出在哪里吗?

import {NgModule} from '@angular/core';
//ERROR IF: import {ServerModule} from '@angular/platform-server';
import {BrowserModule} from '@angular/platform-browser';
import {RouterModule, Routes} from '@angular/router';
import {HttpModule} from "@angular/http";
...
imports: [
    RouterModule.forRoot(
        appRoutes,
        {enableTracing: true}
    ),
    BrowserModule.withServerTransition({
        appId: 'ng-cli-universal'
    }),
    HttpModule /* ERROR IF; , ServerModule*/

],

0 个答案:

没有答案