Corner Router - not working a second time

In this plunk, I have a ui-router $state.gotothat only works for the first time, although I zoom in seqto force a reboot. Make sure the time stamp does not change. What is wrong with this code?

HTML

<body ng-controller="MyCtrl">
    <button ng-click="goto()">Go to state</button>
    <div ui-view=""></div>
</body>

HTML status

  <div>
    {{time1}}
  </div>

Javascript

var app = angular.module("app", ['ui.router']);

app.controller('MyCtrl', function($scope,$state) {

var seq = 0;

$scope.goto = function(){

    alert('about to go to state - ' + seq) ;

        var params = { 
                seq: seq++ 
               };

        $state.go ( 'state1', params );

  };
});

app.controller('state1Ctrl', function($scope) {

      $scope.time1 = new Date();

});


app.config(function($stateProvider) {

  $stateProvider
    .state('state1', {
         templateUrl: 'state1.html',
         controller: 'state1Ctrl'
    });

});
+4
source share
2 answers

Since you do not actually change the state (i.e. you click state1each time, just with a different parameter), you need to pass the third parameter parameter with{reload: true}

$state.go('state1', params, {reload: true});

Your plnkr updated

See the documentation for$state.go(to, params, options)

( , )

params , , reload. :

$stateProvider
  .state('state1', {
    templateUrl: 'state1.html',
    controller: 'state1ctrl',
    params: {
      seq: {}
    }
  });

$stateProvider reloadOnSearch = true, , , , reloadOnSearch: false

+4

params, $stateProvider :

 $stateProvider
    .state('state1', {
         templateUrl: 'state1.html',
         params: { 'seq': null },
         controller: 'state1Ctrl'
    });
0

All Articles