AngularJS - How do I change the State from Inside the Controller

后端 未结 1 1505
醉酒成梦
醉酒成梦 2021-02-03 19:18

I am new to AngularJS and would like to know how I change the State from within the Controller.

For example, I typically change the state on a button click:



        
相关标签:
1条回答
  • 2021-02-03 19:59

    inject $state service to your controller, then in your controller...

    CONTROLLER

    $scope.changeState = function () {
        $state.go('where.ever.you.want.to.go', {stateParamKey: exampleParam});
    };
    

    and add ng-click to your button

    HTML

    <button ng-click="changeState()">Change State</button>
    
    0 讨论(0)
提交回复
热议问题