我想在用户点击按钮时打开一个新窗口,代码如下:
protected assignActity(type: string): void {
var window = window.open('/#/link');
this.Service.assignActivity(type).subscribe(res => {
window.location = '/#/link/' + res;
console.log(res);
})
}
但是它报错了:
core.umd.js:3468 TypeError: Cannot read property 'open' of undefined
如何纠正以使其正常工作?
window.open('some url');
可以工作,但如果您想使用angular-universal,最好避免直接操作窗口。 - maxime1992isBrowser
。因此,使用DI将此变量注入到您的应用程序中,以便您可以从任何地方使用它。然后,当您需要使用window.open
时,只需像这样包装它:if (isBrowser) { window.open('some url) }
- maxime1992