Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have Angular ng-href bind variables within a string

I'd like to bind a links href property to a variable in my controller but I'd also like to have that url be bound to variables. I'd like to accomplish this using the built in binding and without having to manually watch for changes and reload the url. Is this possible?

// In the controller
$scope.section = 'section1';
$scope.page = 'page1';
$scope.url = 'http://myurl/{{section}}/{{page}}';


<!-- In the template -->
<a ng-href="{{url}}">Page Link</a>

This is a simplification of my actual code. Declaring the url pattern in the template would work but I need to have the url be defined in a string that gets passed in.

like image 609
Stephen Marsh Avatar asked Feb 11 '23 02:02

Stephen Marsh


1 Answers

Just set the ng-href

<a ng-href="http://myurl/{{section}}/{{page}}">Page Link</a>
like image 120
tymeJV Avatar answered May 08 '23 09:05

tymeJV