Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Location object in TypeScript

I'm having trouble redirecting my app outside of Angular to the logout page. I'm doing it by using $window.location.href but it's not working on FireFox. So, There was a suggestion to use $window.location directly but since i'm writing in Typescript i need to create a new Location object rather then just assign my string to it...

I looked into lib.d.ts and i saw that location is declared as:

declare var Location: {
    prototype: Location;
    new(): Location;
}

so i adjust my code to:

var url: string = "http:\\\\host:port/blabla/logout";
var loc: Location = new Location();
loc.href = url;
this.$window.location = loc;

but got this error:

Error: Illegal constructor.

Any Idea how to create the Location object? Is it a good practice to do so? Any other insights maybe?

Thanks

like image 235
Rivi Avatar asked Mar 15 '23 22:03

Rivi


1 Answers

It actually looks like you're not supposed to build new Location objects. So I don't think there's a constructor available anywhere for this. Though you can use anchors to build them for you.

If you're trying to set a new location, you can go with setting window.location.href instead of window.location (These two are equivalent).

like image 189
rtpg Avatar answered Mar 20 '23 12:03

rtpg