Anguarr 14 ReferenceError:未定义窗口



我想在我的项目中使用angular universal。Affter i added it i see error:

ReferenceError: window is not defined

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

我已经看到模拟问题:Angular 9 Universal ReferenceError:窗口没有定义,它的答案没有帮助。

使用isPlatformServer通过检查封装代码

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:中

<!-- Remove the component from the DOM -->
<ng-carousel *ngIf="!isServerSide"></div>

最新更新