0

I am learning what logic to put in Angular's various components, but am left unsure of the Angular-way to handle manipulation of the $location.

I have some code that I would like to convert to Angular. It takes the document.referrer and based on various factors, may scroll to an anchor in the page (/page#scrollTo).

Where would one put the logic for this in Angular? It does not seem suitable for a controller.

Kohjah Breese
  • 4,008
  • 6
  • 32
  • 48

1 Answers1

1

For your anchor scroll example, Angular provides an $anchorScroll service: https://docs.angularjs.org/api/ng/service/$anchorScroll. In the docs example, $anchorScroll is used within a $controller. This would be a simple solution when using angular-route.js.

If instead using angular-ui-router.js, then scrollTo's would likely be handled by the $urlRouteProvider. This SO answer: What is the difference between angular-route and angular-ui-router? provides good info about the added functionality of ui-router.

Community
  • 1
  • 1
Scott Rice
  • 2,430
  • 22
  • 18
  • Thank you. It is quite a lot to get your head around for beginners. I did not know of the anchor scroll service. Very useful. – Kohjah Breese Aug 24 '14 at 19:54