title: scope and controller instantiation with ui router
body: <p>I am confused about when controllers get instantiated. Also, how do controllers gets instantiated when nesting states. I might be confused how scope gets attached to view and controller, that is, if every view gets its own controller and scope or do they share the same scope.</p>
  
  <p>Can someone please explain when controllers get instantiated? Under nested routes do all the views share one controller and scope? What happens when I switch states and go back to a state does another controller get instantiated?</p>
  
  <p>Below are my routes(config file ):</p>
  
  <pre><code>.config (googleAnalyticsCordovaProvider, $stateProvider, $urlRouterProvider, IdleProvider, KeepaliveProvider) -&gt;
  
     $stateProvider
  
    .state('app', {
      url: '/app',
      abstract: true,
      templateUrl: 'templates/menu.html',
      controller: 'AppController'
    })
  
    .state('app.pincode', {
      url: '/pincode',
      views: {
        menuContent: {
          templateUrl: 'templates/pincode-yield.html',
          controller: 'PincodeController'
        }
      }
    })
  
    .state('app.pincode.create', {
      url: '/create',
      views: {
        pincode: {
          templateUrl: 'templates/pincode-create.html',
          controller: 'PincodeController'
        }
      }
    })
  
    .state('app.pincode.pincodeLogin', {
      url: '/login',
      views: {
       pincode: {
          templateUrl: 'templates/pincode-login.html',
          controller: 'PincodeController'
        }
      }
    })
  
    .state('app.pincode.settings', {
      url: '/settings',
      views: {
        pincode: {
          templateUrl: 'templates/settings.html',
          controller: 'PincodeController'
        }
      }
    })
  </code></pre>