4

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

2 Answers 2

5

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).

Sign up to request clarification or add additional context in comments.

Comments

4

If you want to assign a String directly and just make TypeScript go along with that, you can do

 window.location = <any>"http://host:port/blabla/logout";

2 Comments

Not sure if you can create a Location object at all. The DOM documentation just mentions that you can get it from window.location and document.location and that you can assign a string to it.
Why is this the accepted answer? I need a second location object, manipulate some properties and use the resulting url without changing the current location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.