1

When i try to go to just opened link, $routeProvider doestn't start the controller again.

Example:

  • in html code I have some links(dynamically), for example url1, url2, url3.
  • when I click on url2, $routeProvider starts the controller.
  • after some time, If I click again on this link - controller doesn't get started (only works for different links)

How to force start the controller, when clicked on just opened link? Or run init code for all links on click(but after this go to target link)?

Ravi Shankar Bharti
  • 8,922
  • 5
  • 28
  • 52
  • according to http://stackoverflow.com/questions/16150289/running-angularjs-initialization-code-when-view-is-loaded , it looks that on every view load the controller indeed does get reloaded – phil294 Jan 31 '17 at 20:00

2 Answers2

0

Can you post your example? Based on how you have configured your $stateProvider might be the problem.

user3236101
  • 78
  • 3
  • 14
0

Use $route.reload();

From the Docs:

$route.reload();

Causes $route service to reload the current route even if $location hasn't changed.

As a result of that, ngView creates new scope and reinstantiates the controller.

-- AngularJS $route API Reference - reload

georgeawg
  • 48,608
  • 13
  • 72
  • 95