title: Strange behavior of $routeChangeSuccess: Not triggering on first load (but not throwing any error)
body: <p>I have no clue how to even begin explaining this situation but I'll try my best. I have a simple Spanish-English-Spanish dictionary lookup page with a text box, a <strong>Lookup</strong> button, and a div to show the results. When you enter a word to lookup in the text box and hit <strong>Lookup</strong>, the results are shown in the div below.</p>
  
  <p>In the results some words are hyperlinked so when you click on them, you get the search result for the clicked word in the div. That's just like any online dictionary service functions. It works perfect except that the second functionality doesn't seem to work on the first click after a typed search. For example:</p>
  
  <p>You type <strong>pedir</strong> in the input box and hit <strong>Lookup</strong>. The div below now shows the detailed meaning of <strong>pedir</strong> including hyperlinked words like <strong>ask</strong>, English for <strong>pedir</strong>. Now, you click <strong>ask</strong> which should refresh the div and show you the Spanish meanings of <strong>ask</strong> including words like <strong>pedir</strong>. However, it just refreshes the div and shows the same content as if you looked up <strong>pedir</strong> a second time. But when you click on <strong>ask</strong> a second time now, it works fine as expected. It must be noted that the words are hyperlinked appropriately and there's no mis-linking going on here. Not only that, other links (such as the ones on the navigation tab on top) also don't seem to work on first click. This happens every time a new word is looked up.</p>
  
  <p>Hope the above example illustrates the problem well enough; at least that's what I have tried. My routing and controllers look like this:</p>
  
  <pre><code>var asApp = angular.module('asApp', ['ngRoute']);
  asApp.config(function($routeProvider) {
      $routeProvider
  .when('/', {
              title: 'Home of thesite – Radical Spanish learning tips and tricks for the adventurous learner',
              templateUrl : 'pages/home.html',
              controller  : 'mainController'
          })
  // route for dictionary
          .when('/dictionary', {
              title: 'The dictionary',
              templateUrl : 'pages/dictionary.html',
              controller  : 'mainController'
          })
  
          // route for dictionary term
          .when('/dictionary/:word2lookup', {
              title: 'The thesite dictionary',
              templateUrl : 'pages/dictionary.html',
              controller  : 'dictController'
          })
  
          // route otherwise
          .otherwise({
              title: 'thesite – Radical Spanish learning tips and tricks for the adventurous learner',
              templateUrl : 'pages/home.html',
              controller  : 'mainController'
          });
  
  });
  
  function HeaderController($scope, $location) 
  { 
      $scope.isActive = function (viewLocation) { 
          return viewLocation === $location.path();
      };
  }
  
  asApp.run(['$rootScope', '$route', '$location', function($rootScope, $route, $location) {
  $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
      document.title = 'Translation of ' + $route.current.params['word2lookup'] + ' | ' + $route.current.title;
  });
  }]);
  
  asApp.controller('mainController', function($scope) {});
  asApp.controller('dictController', function($scope, $routeParams){});
  </code></pre>
  
  <p>I don't even know if I can reproduce the entire situation in a fiddle since it involves some significant server-side scripting.</p>
  
  <p>Please let me know if there's anything I could explain in order for someone to identify the gremlin breaking down my code's functionality.</p>
  
  <p><strong>P.S.</strong>: This issue only affects the first click (on any link on the page) <em>after</em> a new search has been performed, i.e. a word is entered in the input box and the Lookup button is clicked.</p>
  
  <p><strong>Update</strong>: In response to @gr3g's request, here's the code for the functions <code>lookup_check()</code> and <code>lookup_word()</code>:</p>
  
  <pre><code>function lookup_check(lookupterm){
      close_kb();
      if(lookupterm != ""){
          lookup_word(lookupterm);
      }
      else{
          var lookup_box = $('#word');
          lookup_box.addClass('empty');
          setTimeout(function(){ lookup_box.removeClass('empty'); },500);
      }
  }
  // Query dictionary and populate meaning div
  function lookup_word(lookupword){
      var mean = document.getElementById('meaning');
      var waittext = '&lt;div class="preloader-image"&gt;&lt;br /&gt;&lt;br /&gt;';
      var hr = createXMLHTTPRequestObject();
      var url = 'bootstrap/php/dictengine.php';
      var vars = "lookup_word=" + lookupword;
      document.getElementById('word').value = lookupword;
      hr.open("POST", url, true);
      hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      hr.onreadystatechange = function(){
          if(hr.readyState == 4 &amp;&amp; hr.status == 200){
              var return_data = hr.responseText;
              mean.innerHTML = return_data;
              if ($(".el")[0]){ hist_mean = $('.el:first').text(); }
              else { hist_mean = ""; }
              add2local(lookupword, hist_mean);
              $(".tab-container").addClass("hide-tabs");
              if($("#dict_span").length != 0) {
                  $(".tab-container").removeClass("hide-tabs");
                  // logic to seggregate spanish and english results
                  $("#dict_eng").addClass("hide-div");
                  $("#sp_tab").addClass("active");
                  $("#en_tab").removeClass("active");
              }
              document.title = 'Translation of ' + lookupword + ' | The thesite dictionary';
              $("&lt;hr class='dict-divider'&gt;").insertAfter(".gram_cat");
              $("&lt;hr class='dict-divider'&gt;").insertAfter(".quickdef");
              $("&lt;hr class='dict-divider'&gt;").insertBefore(".dict_source");
              $('div.entry_pos').wrap('&lt;div class="pos"&gt;&lt;/div&gt;');
              $('a.dictionary-neodict-first-part-of-speech').wrap('&lt;div class="pos"&gt;&lt;/div&gt;');
              // update url
              var loc = window.location.href;
              var lastpart = loc.substring(loc.lastIndexOf('/') + 1);
              if(lastpart == 'dictionary'){ window.location.replace(window.location.href + "/" + encodeURI(lookupword)); }
              if((lastpart != 'dictionary') &amp;&amp; (lastpart != encodeURI(lookupword))){
                  var addr = window.location.href;
                  var addrtemp = addr.substring(addr.lastIndexOf('/') + 1);
                  addr = addr.replace(addrtemp, encodeURI(lookupword));
                  if(!!(window.history &amp;&amp; history.pushState)){ history.pushState(null, null, addr); }
                  else{ window.location.replace(addr); }
              }
          }
          //else { setTimeout('lookup_word(lookupword)', 1000); }
      }
      hr.send(vars);
      mean.innerHTML = waittext;
  }
  </code></pre>
  
  <p><strong>Update 2</strong>: To further facilitate @gr3g, here's <code>dictionary.html</code>:</p>
  
  <pre><code>&lt;!-- dictionary.html --&gt;
  &lt;script&gt;
      var loc = window.location.href;
      var lastpart = loc.substring(loc.lastIndexOf('/') + 1);
      if(lastpart != 'dictionary'){ lookup_check(decodeURI(lastpart)); }
  
      // populate search history if available
      var recent = document.getElementById('recent-lookups');
      var value = localStorage.getItem('w');
      if (value) {
          value = JSON.parse(value);
          var len = value.length - 1;
          var str = "";
          for (a=len; a&gt;=0; a--){
              term = value[a].substr(0, value[a].indexOf('$'));
              term_meaning = value[a].substr(value[a].indexOf("$") + 1);
              if(term_meaning != "") {
              str = str + "&lt;p&gt;&lt;strong&gt;&lt;a href='/a-s/#/dictionary/" + encodeURI(term) + "'&gt;" + term + "&lt;/a&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&lt;i class='fa fa-chevron-right' style='color: #a5a5a5;font-size: 80%;'&gt;&lt;/i&gt;&amp;nbsp;&amp;nbsp;&lt;span class='recent_meanings'&gt;" + term_meaning + "&lt;/span&gt;&lt;/p&gt;";
          }
              else { str = str + "&lt;p&gt;&lt;em&gt;" + term + "&lt;/em&gt;&lt;/p&gt;"; }
          }
          recent.innerHTML = str;
      }
      else { recent.innerHTML = "&lt;p&gt;No historical data to show right now. Words will start appearing here as you begin your lookups.&lt;/p&gt;"; }
  
      // populate word of the day on pageload
      wotd();
  
  &lt;/script&gt;
  
  &lt;!-- top-image start --&gt;
  &lt;div class="page-header-line-div"&gt;
  &lt;/div&gt;
  &lt;!-- top-image end --&gt;
  &lt;br&gt;
  &lt;br&gt;
  
  &lt;div class="container-fluid" ng-controller="luController as luCtrl"&gt;
      &lt;div class="row row-padding"&gt;
          &lt;form class="form-horizontal" role="form" name="lookup-form" id="lookup-form" action="" method=""&gt;
              &lt;div class="input-group col-md-6"&gt;
                  &lt;input  id="word" type="textbox" placeholder="Enter a Spanish or English word here..." class="form-control input-lg lookup-field lookup-field-single" onMouseOver="$(this).focus();" required ng-model="luCtrl.lookuptrm"&gt;
                  &lt;i class="fa fa-times fa-lg delete-icon" onfocus="clearword();" onclick="clearword();" data-toggle="tooltip" data-placement="top" title="Click to clear entered text"&gt;&lt;/i&gt;
                &lt;i class="fa fa-keyboard-o fa-2x kb-icon" onfocus="toggler('virtualkeypad', this);" onclick="toggler('virtualkeypad', this);" data-toggle="tooltip" data-placement="top" title="Click to enter accented characters"&gt;&lt;/i&gt;
                  &lt;div class="input-group-btn"&gt;
                      &lt;button class="btn btn-lg btn-primary lookup-submit" type="submit" id="lookup" ng-click="luCtrl.handlelookup(luCtrl.lookuptrm)"&gt;Lookup&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div id="virtualkeypad" class="btn-group vkb-hide"&gt;&lt;!--col-md-offset-4--&gt;
                &lt;button class="btn btn-lg first-btn" type="button" onClick="spl_character('á');"&gt;á&lt;/button&gt;
                &lt;button class="btn btn-lg" type="button" onClick="spl_character('é');"&gt;é&lt;/button&gt;
                &lt;button class="btn btn-lg" type="button" onClick="spl_character('í');"&gt;í&lt;/button&gt;
                &lt;button class="btn btn-lg" type="button" onClick="spl_character('ó');"&gt;ó&lt;/button&gt;
                &lt;button class="btn btn-lg" type="button" onClick="spl_character('ú');"&gt;ú&lt;/button&gt;
                &lt;button class="btn btn-lg" type="button" onClick="spl_character('ü');"&gt;ü&lt;/button&gt;
                &lt;button class="btn btn-lg last-btn" type="button" onClick="spl_character('ñ');"&gt;ñ&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  
          &lt;!-- tabbed view for bilingual words --&gt;
          &lt;div class="col col-md-8 bi"&gt;
              &lt;ul class="nav nav-tabs tab-container hide-tabs lang-tabs" role="tablist"&gt;
                  &lt;li class="nav active" id="sp_tab" onClick="$(this).addClass('active'); $('#en_tab').removeClass('active'); $('#dict_eng').addClass('hide-div'); $('#dict_span').removeClass('hide-div');"&gt;&lt;a href="" data-toggle="tab"&gt;Spanish&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="nav" id="en_tab" onClick="$(this).addClass('active'); $('#sp_tab').removeClass('active'); $('#dict_span').addClass('hide-div'); $('#dict_eng').removeClass('hide-div');"&gt;&lt;a href="" data-toggle="tab"&gt;English&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
              &lt;div class="dictionary-result" id="meaning"&gt;
                  &lt;p class="box-text"&gt;This bilingual dictionary is an actively growing resource accumulating new words each day. Currently drawing from the best names in the world of Spanish/English dictionary, such as &lt;strong&gt;Collins&lt;/strong&gt;&lt;sup&gt;®&lt;/sup&gt; and &lt;strong&gt;Harrap&lt;/strong&gt;&lt;sup&gt;®&lt;/sup&gt;, it continues to improve with every lookup you perform. It includes regionalism, colloquialism, and other non-standard quirkiness from over a dozen Spanish dialects ranging from Peninsular to Mexican and Argentinean to Cuban. This dictionary also includes a growing number of specialty terms specific to niches such as medicine, economics, politics, etc.&lt;/p&gt;
                  &lt;p class="box-text"&gt;Please use this page only for dictionary lookups and not comprehensive translations. You can enter either English or Spanish terms and the dictionary will automatically guess the language it belongs to. Keep your inputs to within 20 characters (that should be long enough to handle any English or Spanish word you might want to look up).&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
  
  
          &lt;!-- sidebar --&gt;
          &lt;div class="col col-md-4"&gt;
              &lt;!-- history panel --&gt;
              &lt;div class="panel panel-default panel-box card-effect"&gt;
                &lt;div class="panel-heading panel-title"&gt;Recent Lookups&lt;/div&gt;
                &lt;div id="recent-lookups" class="panel-body panel-text"&gt;
                  No historical data to show right now. Words will start appearing here as you begin your lookups.
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;!-- WOTD panel --&gt;
              &lt;div class="panel panel-default panel-box card-effect"&gt;
                &lt;div class="panel-heading panel-title"&gt;Word of the Day&lt;/div&gt;
                &lt;div id="wotd" class="panel-body panel-text"&gt;
                  Word of the day not currently available.
                &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>