首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReferenceError 14 :窗口未定义

ReferenceError 14 :窗口未定义
EN

Stack Overflow用户
提问于 2022-09-13 09:02:54
回答 1查看 53关注 0票数 0

我想在我的项目中使用角万向盘。我补充说,我看到了错误:

代码语言:javascript
复制
ReferenceError: window is not defined

我没有在我的项目中使用window,但是它可能在30部分库中使用。如何解决这个问题?

我已经看到了模拟问题:Angular 9 Universal ReferenceError: window is not defined --它的答案没有帮助。

EN

回答 1

Stack Overflow用户

发布于 2022-09-16 13:38:01

使用isPlatformServer通过检查封装代码

代码语言:javascript
复制
export class ArtistShowComponent {
  constructor(@Inject(PLATFORM_ID) private platformId: Object) {
    this.isServerSide = isPlatformServer(platformId);
  }

  isServerSide: boolean;

  doSomething() {
    // If the issue is in typescript
    if (this.isServerSide) {
      ...
    }
  }
}

如果问题位于第三方角组件/HTML中:

代码语言:javascript
复制
<!-- Remove the component from the DOM -->
<ng-carousel *ngIf="!isServerSide"></div>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73700243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档