我目前正在尝试使用 SSR 将轮播添加到我的 Angular 17 应用程序中。 我尝试添加的轮播是此页面的第一个: https://coreui.io/angular/docs/components/carousel 我是 Angular 的新手,我发现使用 SSR,我们无法使用窗口对象。但错误来自 coreui,因为在不使用 coreui 模板的情况下,我的应用程序运行良好。 我将错误添加到附件中。 感谢您的帮助!我尝试了一些东西,但遗憾的是我还不够好
文档的轮播形式应该已成功显示,但我却出现了窗口错误
编辑:我找到了解决这个问题的方法。
仅当导航器播放时我才会渲染轮播部分
在 component.typescript 文件上:
isBrowser: boolean;
constructor(@Inject(PLATFORM_ID) private platformId: object) {
this.isBrowser = isPlatformBrowser(this.platformId);
}
在 component.html 上:
@if (isBrowser) {
code...
}