Search code examples
angularjsmobile-angular-ui

how to change mobile-angular-ui "ui-state" from controller code


I am maintaining a state as follows

<ui-state id='activeScreen' default='1'></ui-state>

I am able to change the state as follows

<a href="#" ui-set="{'activeScreen': 2}">click here</a>

How to change the state from the controller code?


Solution

  • You need to use the SharedState service:

    app.controller('myController', function($scope, SharedState){
      SharedState.initialize($scope, "activeScreen", 2);
    });
    

    Or:

    app.controller('myController', function($scope, SharedState){
      SharedState.set("activeScreen", 2);
    });