angular

Angular-UI UI-Router reload same Controller with $state.transitionTo()

TAGs: 0 Comment

Posted By: eligeske on in angular

Why: While creating a search bar on the main menu of a site. I was using a global param to set the search params to be used in the result list. But the cotroller does not fire again if the url is the same.

How: Using $state.transitionTo(“router name to controller here”, $stateParams, $options) to refire that controller. Look below and see the that transitionTo $options has reload = true and notify = true.

Example: 

var routes = function($stateProvider, $urlRouterProvider){
 $stateProvider
     .state("home",{
         url: "/home",
         controller: function($scope, $state) {
             $scope.search = function(){
                 $state.transitionTo("results", { myParam: "hello" }, { notify: true }); 
             }
         } 
     }).
     .state("results",{
         url: "/results/:myParam",
         controller: function($scope, $state){
 
         } 
     })
 }

 

Plunker Example <——

0 Responses to "Angular-UI UI-Router reload same Controller with $state.transitionTo()"

"SHARING IS CARING"

Comments are closed.

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post