我尝试在延迟加载模块中呈现来自 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>