Anky
Anky

Reputation: 270

how to refresh page to fetch new values from service using angular?

i am having a page having 1 table and 2 charts , how would i refresh my charts and tables while pressing a refresh button , as my table and 2 different charts are coming from 3 different controllers on a single page . i want to refresh all of them so they would be able to get new values from the webservice again and recreate the page accordingly with the click or the single refresh button .

i have tried few ideas also .

$scope.refreshChart = function(){
    alert("refresh"); 
    // $scope.dashloader = true;
  $state.go('plm.creator');
  // $scope.dashloader = false;
   console.log("On page refresh called; not from dashboard page");


}

but these are not working as per my expectations , kindly help

Upvotes: 0

Views: 309

Answers (2)

Cleverguy25
Cleverguy25

Reputation: 503

One thing you can try is to use $scope.$broadcast(name, args) to broadcast an event (event name is just a string you make up) that all the controller can listen for and then run their code to refresh.

The controller listen with $scop.$on(event, listener)

So one controller would do this:

$scope.$broadcast('MyRefreshEvent', args);

and another controller would do this:

$scope.$on('MyRefreshEvent', function (args) {
    //handle refresh
});

Upvotes: 1

k102
k102

Reputation: 8079

You can reload the full page using this:

$state.transitionTo($state.current, $stateParams, {
            reload: true,
            inherit: false,
            notify: true
        });

But I don't recommend to do so, I guess you can do some refactoring to end up with one controller depending on number of factories.

Upvotes: 1

Related Questions