3

Is it possible to set ng-href to go to the current page?

eg:

<a ng-href="https://www.facebook.com/sharer/sharer.php?u={{ window.location.href }}">facebook</a>

When the above runs, I keep getting:

<a ng-href="https://www.facebook.com/sharer/sharer.php?u=" href="https://www.facebook.com/sharer/sharer.php?u=">facebook</a>
Aᴍɪʀ
  • 7,623
  • 3
  • 38
  • 52
John Fu
  • 1,812
  • 2
  • 15
  • 20

2 Answers2

1

How are you setting value to window.location.href ? This sure doesn't look like native JS.

Here's a fiddle to help you out.

Aniket Sinha
  • 6,001
  • 6
  • 37
  • 50
  • Thanks Aniket. That's exactly what I ended up doing half an hour after I asked the question. Before that, I was beating around the bush hoping that by putting {{ window.location.href }}, it would automatically compute the js within the double brackets. :P – John Fu Jan 29 '15 at 22:43
-2

ng-href is part of AngularJS and there are a few ways to point to the same page. The method I use do not include the domain so the Angular Router will direct it as needed, like the following.

ng-href="/mySubDomain"

The Docs go into detail about this and give a nice code sample that shows you what you should expect from the route change.

https://docs.angularjs.org/api/ng/directive/ngHref

Michael Warner
  • 3,879
  • 3
  • 21
  • 45