0

I am using Angular's UI Router and I am looking to create a $scope function (ultimately to pass to the view to have a ng-click call it) to reload a controller and its associated resolver. How would I do this?

I've tried this but it doesn't seem to reload the resolver:

$scope.reloadMe = function() {
    $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true });
};
Matt
  • 2,317
  • 7
  • 41
  • 52

2 Answers2

1

just inject $route into the controller and call $route.reload so the code would look like:

$scope.reloadMe = function () {
  $route.reload();
};

You can read the documentation here: https://docs.angularjs.org/api/ngRoute/service/$route

link
  • 2,480
  • 1
  • 16
  • 18
0

You can inject $injector and load $state to reload. Here I put two examples, you can use one of them.

function MyController($injector, data) {
    $injector.get('$state').reload(); // this reload all states and controllers scopes
    // or
    $injector.get('$state').go($state.current, {}, {reload: true}); // second parameter is for $stateParams
}

Otherwise, in case i need to reload the page, i use javascript

window.location.reload() 

This question is asked here

Community
  • 1
  • 1
Mateo Marconi
  • 614
  • 5
  • 16