AngularJS - help with ng-bind URL

Hi..
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('http://www.cnn.com');'>LINK</a>"

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

 Any ideas what's wrong with myURL string?

 
               
     

    formatter.GotoLink = function (url){
        window.open(link,'_system');
    }
LVL 1
JElsterAsked:
Who is Participating?

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

x
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:
Hi,

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('http://www.cnn.com');
})

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.

Giannis
0
JElsterAuthor Commented:
How can I click on the link and call a function()?
I need to click on the link and pass the URL.
thanks!
0
Ioannis ParaskevopoulosCommented:
You can try the following:

On your view:
<a href="#" ng-click="setUrl('http://www.cnn.com')">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){
		$window.location=url;
	}
})

Open in new window


Giannis
0

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
JavaScript

From novice to tech pro — start learning today.