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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.