title: Ui-router loads state, then how can I run a function?
body: <p>I'm new to Angular and states and wrapping my head around ui-router. I've been doing it with jQuery for too long. In jQuery, I can load up something with ajax, then on the success, perhaps run another function. How do you do that with Angular?</p>
  
  <p>For example, I have the following </p>
  
  <pre><code>var ivApp = angular.module('ivApp', ['ui.router']);
  
  ivApp.config(function($urlRouterProvider, $stateProvider){
  
    $urlRouterProvider.otherwise('/');
  
    $stateProvider
      .state('home', {
        url: '/',
        templateUrl: 'partials/partial-home.html'
      })
  
   });
  </code></pre>
  
  <p>Which simply loads up <code>partial-home.html</code> into my <code>ui-view</code>. But how to tell it to run a function once that is done? For example, I have <code>authenticate.js</code> and a function <code>authenticate()</code>. How do I run authenticate() once 'home' state has loaded?</p>
  
  <p>Additionally, can I tell angular to only load authenticate.js for this state? Or should I have already loaded it in the template. I know that if I include the script in partial-home.html (e.g. <code>&lt;script src="authenticate.js"&gt;&lt;/script&gt;</code>) chrome throws me an error about synchronous xmlhttprest being deprecated. So somhow in the config, can I declare authenticat.js as a dependency of the state or something like that?</p>
  
  <p>At the moment I have worked out I can do something like:</p>
  
  <pre><code>ivApp.controller('authenticate', function($scope) {
  
    // start authorisation
    authenticate();
  
  });
  </code></pre>
  
  <p>And then define the controller authenticate in my ui-router states. But is that how it's done? It works basically. My authenticate function is doing things like changing things in the DOM, but I read controllers shouldn't be used for this.</p>
  
  <p>Thanks for any pointers</p>