moh_abk
moh_abk

Reputation: 2164

Print result of js function in href

Can anyone help please;

I have the below;

<a href="search-menu/{{data.id}}/{{data.name}}">

data.id & data.name are from ng-repeat

I've this function which makes sentence SEO friendly

slug = getSlug("Unfriendly Name");
console.log(slug); // Output: unfriendly-name

How can I use this in my href?

Something like;

<a href="search-menu/{{data.id}}/javascript:getSlug({{data.name}})">??

Thanks

Upvotes: 0

Views: 50

Answers (1)

MayK
MayK

Reputation: 1329

instead of href use ng-href

<a ng-href="search-menu/{{data.id}}/getSlug(data.name)">

you can also make a function in your controller that will return the whole string.

<a ng-href="your wholeStringFunction(data.id, data.name)">

Upvotes: 1

Related Questions