Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open an URL in a new tab

Tags:

angular

I know there is a $window service in Angular 1.x. Now, I want to open an URL in a new tab, I haven't found any service to do this.

UPDATE:
Seems Angular 2 itself doesn't provide a method/service like Angular 1.x. If you want to navigate inside of an Angular app, you can refer to Angular Router - navigate(). I'm asking this question because I want to navigate using some method provided by Angular, but none of the answers is what I expect.

like image 755
Lolo. Avatar asked Dec 16 '15 06:12

Lolo.


1 Answers

It sounds like the OP wanted to know how to use $window in angular2 to open a link in either a new tab or window - not to distinguish between them. In case this helps anyone, first declare window:

interface MyWindow extends Window {
    myFunction(): void;
}

declare var window: MyWindow;

then open the link as usual

window.open(url);
like image 194
Dovev Hefetz Avatar answered Oct 02 '22 03:10

Dovev Hefetz