Open In App

How to Open URL in New Tab using Angular ?

Last Updated : 07 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn How to open a link in a new tab using Angular. A Link is a connection from one web page to another web page. Generally, the anchor tag can be used to open URLs in a new tab in an elementary and straightforward manner. However, the window.open() method can also be utilized to open a new browser window or a new tab depending on the browser setting and the parameter values.

Steps for Installing & Configuring the Angular Application

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Project Structure

It will look like the following:

z123

Example 1: In this example, we will use a function window.open to open the link in a new tab.

HTML
<!-- app.component.html -->
<h2 style="color: green">GeeksforGeeks</h2>
<h2>How to open a link in new tab using angular? </h2>
<a (click)=
"goToLink('https://www.geeksforgeeks.org/geeks-premier-league-gpl-2023/') "
   href="">
    Geeks Premier League
</a>
JavaScript JavaScript

Output:

Example 2: In this example, we will be using target="_blank".

HTML
<!-- app.component.html -->
<h2 style="color: green">GeeksforGeeks</h2>
<h2>How to open a link in new tab using angular? </h2>
<a href=
"https://www.geeksforgeeks.org/geeks-premier-league-gpl-2023/"
   target="_blank">
    Geeks Premier League
</a>
JavaScript JavaScript

Output


Next Article

Similar Reads