AngularJS - help with ng-bind URL

I'm trying to bind a var which contains an URL and ng-click.

I'm binding this url - but it doesn't show as a hyperlink.

var myURL = "<a ng-click='formatter.GotoLink('');'>LINK</a>"

 it appears literally ...  like "<a ng-click='formatter.GotoLink('');'>LINK</a>"
instead of "LINK"

 Any ideas what's wrong with myURL string?


    formatter.GotoLink = function (url){,'_system');
Who is Participating?
Ioannis ParaskevopoulosCommented:
You can try the following:

On your view:
<a href="#" ng-click="setUrl('')">Link</a>

Open in new window

and on your controller (you will need to inject $window service):
module.controller('mainCtrl',function($scope, $window){
	$scope.setUrl = function(url){

Open in new window

Ioannis ParaskevopoulosCommented:

May i suggest a different approach?

From what you have said it seems that you need a way to bind the href attribute of an anchor to something dynamic.

The way to do this is ingecting $sce service in your controller and then use it to trust the url you enter. Here is an example:

module.controller('mainCtrl',function($scope, $sce){
    $scope.myURL = $sce.trustAsResourceUrl('');

Open in new window

And then in your view:

    <a  ng-href="{{myURL3}}">LINK</a>

Open in new window

So now you do not need to inject html in your view. The html is there waiting for the proper value to be loaded.

JElsterAuthor Commented:
How can I click on the link and call a function()?
I need to click on the link and pass the URL.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.