Linking an external URL with another domain from a partial expression

All I'm trying to do is enable the anchor tag inside the html partial, which links to an external site. If this standard html, the code would be simple:

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

Easier like this, I can’t find a working solution to go through an angular route interception (or maybe replacing my anchor with https://docs.angularjs.org/api/ng/directive/a inadvertently?).

I looked at SO and the rest of the network and saw many solutions for working with: links in one domain, routing in SPA, routing on a page (ala $ anchorScroll), but none of them is my problem for sure.

I suspect this may have something to do with using $ sce, but I'm angular n00b and not quite sure how to use this service correctly. I tried the following in my controller:

$scope.trustUrl = function(url) {
    return $sce.trustAsResourceUrl(url);
}

with appropriate:

<a ng-href="{{ trustUrl(item) }}">Click me!</a>

(as described here: Linking an external url in angularjs pattern )

but that didn’t seem to lead to a trick (I only got href = "{{" on the displayed page).

Using a simple vanilla anchor link:

<a href="http://www.google.com">google</a>

also failed to do the trick (although some online reported that the standard href would result in a full page reload in angular: AngularJS - How can I do a redirect with a full page load? ).

I also tried to add the target = _self attribute, but that also had no effect.

, ?

target = "_blank" angular JS

, , - n00bishness, , , , URL-.

, , .

+4
1

, , . , . , ng-click url :

HTML:

<a class="navLinkHcp" href="{{hcpurl}}" title="Habitat Conservation Plan" target="_blank" ng-click="linkModelFunc(hcpurl)">Habitat Conservation Plan</a>

:

$scope.hcpurl = 'http://eahcp.org/index.php/about_eahcp/covered_species';

$scope.linkModelFunc = function (url){
  console.log('link model function');
  $window.open(url);
}

! . KevinB , , , , .

+6

Source: https://habr.com/ru/post/1546343/


All Articles