I\'m trying to Open a new page when user clicks on a link. I can\'t use Angular 2 Router, because it doesn\'t have any functionalities to redirect to an external URL.
<in HTML:
<a class="main-item" (click)="onNavigate()">Go to URL</a>
OR
<button class="main-item" (click)="onNavigate()">Go to URL</button>
in TS file:
onNavigate(){
// your logic here.... like set the url
const url = 'https://www.google.com';
window.open(url, '_blank');
}
Another possible solution is:
const link = document.createElement('a');
link.target = '_blank';
link.href = 'https://www.google.es';
link.setAttribute('visibility', 'hidden');
link.click();
you can do like this in your typescript code
onNavigate(){
var location="https://google.com",
}
In your html code add an anchor tag and pass that variable(location)
<a href="{{location}}" target="_blank">Redirect Location</a>
Suppose you have url like this www.google.com
without http
and you are not getting redirected to the given url then add http://
to the location
like this
var location = 'http://'+ www.google.com