【问题标题】:Server side not render http requests [Angular Universal]服务器端不呈现 http 请求 [Angular Universal]
【发布时间】:2017-08-02 04:51:10
【问题描述】:

当我执行“查看源代码”时,我无法从 api 的 http 请求中获取任何人员,看起来该人员不是来自服务器。

所以我可以在源代码中看到静态 html,但从 http 请求中看不到任何内容......

有人知道可能是什么问题吗?

我正在使用universal-cli

编辑:

这是来自我的showcode.service.ts 的 http 调用示例:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { environment } from '../../environments/environment';

@Injectable()
export class ShowcodeService {

  constructor(private http: Http) { }

  getCode(id): any{
     return this.http.get(environment.baseUrl + 'code/show/' + id)
        .map((response: Response) => response.json());
  };

}

这里是一个活生生的例子:http://pushsc.com/show/code/58bc83760a58d602a0b99d14 检查 html 的源代码...它渲染了来自 http 的期望的东西...

【问题讨论】:

  • 请发布您的模板和打字稿
  • 您需要什么零件?我使用universal-cli 创建了这样的项目ung new project
  • http 调用的打字稿。
  • 我更新了我的主要问题...从我的服务添加了 http 调用...
  • @Vladimir 你还有这个问题吗?

标签: angular angular-universal universal-cli


【解决方案1】:

尝试将您的角度更新为 4.0.0。

他们修复了一些与服务器端渲染相关的错误。

【讨论】:

  • 我还建议更新到 Angular 4。但是,使用来自 platform-server 的模块和服务,universal-cli (还)不起作用。
  • 我花了半周的时间来克服这个问题,然后开发了一个示例应用程序,以便其他人不会受此困扰:github.com/nglibs/universal-example-app
  • 嗨@BurakTasci你能告诉我你是如何解决htis问题的吗?问题的主要关键。最好的!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-26
  • 2018-06-14
  • 2021-06-11
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
  • 2017-03-07
相关资源
最近更新 更多