Linking an external URL in an angularjs template

I have an angularjs application with a controller and partial connection.

In my controller, I have an array of links.

$scope.links = ['http://www.example.com/1','http://www.example.com/2'];

In my partial, I have the following code.

 <div ng-repeat="link in links">
 <a href="{{link}}" target="_blank">Link</a>
 </div>

This does not work. I run this through a NodeJS application locally .. and so my URLs always end like this: http://dev-server.local:3000/"http://www.example.com"

Can someone please help me figure out how I can add a hyperlink from my controller directly to my incomplete template and make Angular not add the page URL.

+1
source share
2 answers

instead

href={{link}}

using

ng-href={{link}}
+3
source

URL- extern: s. $sce.

, $sce, , URL-.

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

URL-

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

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


All Articles