title: Back Arrow and Angular Routing - Press Back Twice
body: <p>Angularv1.1.5</p>
  
  <p>Site: <a href="http://tilsa.azurewebsites.net" rel="nofollow">http://tilsa.azurewebsites.net</a></p>
  
  <p>I have a very simple route setup however when the user goes from the default/home route to the detail (pregunta) route and then clicks the back button nothing happens.  The 2nd/3rd time the back button is clicked the user returns (chrome) to the default/home route.  I'm not sure as to how or why this is happening.  </p>
  
  <pre><code>$routeProvider.
  when('/', {
      templateUrl: '/js/app/partial/index.html',
      controller: 'IndexCtrl'
  })
  .when('/pregunta/:id', {
      templateUrl: '/js/app/partial/detalle.html',
      controller: 'PreguntaDetalleCtrl'
  }).
  otherwise({
      redirectTo: '/'
  });
  </code></pre>
  
  <p>Here are the two relevant controllers.  I've removed some of the code that doesn't seem relevant (polling for new info/etc):</p>
  
  <pre><code>// load the index list of questions, the actual questions are loaded in parent scope
  
  .controller('IndexCtrl', ['$scope', 'services', 'data', '$modal', 'navigation', 'timeFunctions', function ($scope, services, data, $modal, navigation, timeFunctions)
  {
      $scope.noEncodeUrl = 'http://tilsa.azurewebsites.net/';
  
      $scope.url = encodeURIComponent($scope.noEncodeUrl);
      // controls the back arrow visibility to go back
      navigation.setReturn(false);
  
  }])
  .controller('PreguntaDetalleCtrl', ['$scope', '$routeParams', 'services', 'navigation', 'graphService', 'stringFx', '$timeout', 'timeFunctions',  function ($scope, $routeParams, services, navigation, graphService, stringFx, $timeout, timeFunctions) {
  
      $scope.notas = [];
  
      $scope.comentario = '';
  
      navigation.setReturn(true);
  
      $scope.loadPregunta = function (id, loadComments)
      {
          services.preguntas.getDetalle(id).then(function (data)
          {
              $scope.safeApply(function ()
              {
                  $scope.pregunta = data;
                  graphService.setProp('title', $scope.pregunta.pregunta);
                  $scope.noEncodeUrl = 'http://tilsa.azurewebsites.net/pregunta/' + id;
  
                  $scope.url = encodeURIComponent($scope.noEncodeUrl);
                  $scope.preguntaText = stringFx.removeAccent('¿'+$scope.pregunta.pregunta+'?');
  
              });
  
              if (loadComments)
              {
  
              $scope.commentTracker = {
                  defaults: {             },
                  skip: 0,
                  take: 20
              };
  
              $scope.$on('$destroy', function (e)
              {
                  $scope.stopPolling();
              });
  
              $scope.startPolling = function ()
              {
  
                  // scrollTimeout will store the unique ID for the $setInterval instance
                  return $scope.scrollTimeout = timeFunctions.$setInterval(poll, 10000, $scope);
  
                  // Function called on interval with scope available
                  function poll($scope)
                  {
                      services.preguntas.getNotas($scope.pregunta.id, $scope.commentTracker, $scope.notas).then(function (data)
                      {
  
  
                          $scope.safeApply(function ()
                          {
                              for (i = 0, l = data.notas.length; i &lt; l; i++)
                              {
                                  $scope.notas.unshift(data.notas[i]);
                              }
                          });
  
  
  
                      });
  
                  }
              }
  
              $scope.stopPolling = function ()
              {
                  return timeFunctions.$clearInterval($scope.scrollTimeout);
              }
  
              $scope.startPolling();
  
  
              $scope.cargarAnteriores = function ()
              {
                  //$scope.commentTracker.skip++;
  
                  services.preguntas.getNotas($scope.pregunta.id, $scope.commentTracker, $scope.notas, true).then(function (data)
                  {
                      $scope.safeApply(function ()
                      {
                          $scope.notas = $scope.notas.concat(data.notas);
                          $scope.masNotas = $scope.notas.length &gt; 0;
                      });
  
  
                  });
  
              }
  
              $scope.cargarAnteriores();
              }
  
          });
  
      }
  
  
  
      $scope.notaNueva = function () {
          //$scope.commentario;
  
  
          if ($scope.comentario.length &lt; 3)
          {
              alert('Escribe algo mas, no seas tacano con tus palabras');
              return;
          }
          $scope.processing = true;
  
          services.preguntas.insertNota($scope.pregunta.id, $scope.comentario, $scope.notas, false).then(function (data)
          {
  
              $scope.comentario = '';
              $scope.processing = false;
  
              $scope.loadPregunta($scope.pregunta.id, false);
  
              services.preguntas.getNotas($scope.pregunta.id, $scope.commentTracker, $scope.notas).then(function (data)
              {
  
                  $scope.safeApply(function ()
                  {
                      for (i = 0, l = data.notas.length; i &lt; l; i++)
                      {
                          $scope.notas.unshift(data.notas[i]);
                      }
                  });
  
              });
  
          });
      }
  
      $scope.loadPregunta($routeParams.id, true)
  
      $scope.$on('updatedpregunta', function (event, obj)
      {
          $scope.loadPregunta(obj, false)
  
      });
  
  }]);
  </code></pre>