angular - Angular Universal +lazyLoading 模块 + http 请求
问题描述
我尝试在延迟加载模块中呈现来自 http 响应的数据。SSR 不呈现它的源代码。
当它不在lazyLoading SSR 中时渲染它。
使用lazyLoading路由模块时,有什么方法可以在AngularUniversal中呈现数据?
const routes: Routes = [
{
path: '',
children: [
{
path: 'dane',
loadChildren: () => import('./dane/dane.module').then(m => m.DaneModule) // http reponse not render
}
],
children: [
{
path: 'dane',
component: DaneComponent // http response is render
}
]
},
]
import { HttpClient } from '@angular/common/http';
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
@Component({
selector: 'app-dane',
templateUrl: './dane.component.html',
styleUrls: ['./dane.component.scss']
})
export class DaneComponent implements OnInit {
el: any = {
hero_image: ''
};
constructor(
private http: HttpClient
) { }
ngOnInit() {
this.getData();
}
getData() {
this.http.get('http://localhost:3000/posts').subscribe(data => {
this.el = data;
})
}
}
hero: <b>{{ el.hero_image }}</b>
解决方案
推荐阅读
- android - 导入aar文件,但有两个图标
- bash - 使用 awk 将 kB 转换为 MB
- git - 是否可以在多台机器之间同步本地 Github 存储库?
- php - 关闭选项卡后更新数据库中的注销时间
- java - How to establish network communication between two Java servers
- javascript - 输入范围滑块拇指js事件
- node.js - 地理定位问题,一旦给出结果,其他所有超时
- python - Facebook fasttext bin 模型 UnicodeDecodeError
- jenkins-pipeline - 如何从詹金斯脚本管道创建属性文件
- c# - 在静态 IP 上连续 Ping,如果返回 false,则发送电子邮件