user3737396 user3737396 - 1 month ago 11
AngularJS Question

using default browser behaviour for href and target in an <a> tag in angular2

In angular2, how do you implement the behavior of a simple

<a href="some url" target="_whatever">


without the routing module highjacking the url with the base href?

For example, expected behaviour for the following snippet in an angular template would be to open google in a new tab.

<a href="www.google.com" target="_blank">


What actually happens is angular compiles the template as follows.

<a _ngcontent-kju-6="" target="_blank" ng-reflect-href="www.google.com" href="www.google.com">


Clicking on this opens [the base url]/www.google.com a new tab rather than simply www.google.com

Answer

Prefixing your url with a protocol should give you what you want, e.g. 'http://www.google.com'.

Comments