我无法将我在Angular之外的应用重定向到退出页面。
我是通过使用$window.location.href
来实现的,但它不适用于FireFox。
所以,有一个建议直接使用$window.location
,但由于我在使用Typescript编写,我需要创建一个新的Location对象,而不是只是将我的字符串赋给它...
我查看了lib.d.ts,我看到该位置被声明为:
declare var Location: {
prototype: Location;
new(): Location;
}
所以我将我的代码调整为:
var url: string = "http:\\\\host:port/blabla/logout";
var loc: Location = new Location();
loc.href = url;
this.$window.location = loc;
但得到了这个错误:
Error: Illegal constructor.
任何想法如何创建Location对象?这样做是一种好习惯吗? 还有其他任何见解吗?
由于
答案 0 :(得分:2)
如果你想直接分配一个字符串,只需让TypeScript继续,你就可以
window.location = <any>"http://host:port/blabla/logout";
答案 1 :(得分:1)
实际上看起来你是not supposed to build new Location
objects。所以我认为没有任何构造函数可用于此。虽然你是can use anchors to build them for you。
如果您尝试设置新位置,可以设置window.location.href
而不是window.location
(These two are equivalent)。