title: How to dynamically inject controller in AngularJS
body: <p>How to set <code>ng-controller</code> as an expression from the <code>$scope</code>?</p>
  
  <p>According to the <a href="http://docs.angularjs.org/api/ng.directive%3angController" rel="nofollow">documentation</a>:</p>
  
  <blockquote>
    <p>ngController – {expression} – Name of a globally accessible
    constructor function or an expression that on the current scope
    evaluates to a constructor function.</p>
  </blockquote>
  
  <p>But how to evaluate scope expression as a controller for controllers that have been registered with module <code>.controller</code>?</p>
  
  <p>For example:</p>
  
  <p>Layout:
  </p>
  
  <pre><code>&lt;div ng-controller="myExpr"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JavaScript (define controller):
  </p>
  
  <pre><code>app.controller('myCtrl', ['$scope', '$timeout', function () { ... }];
  </code></pre>
  
  <p>JavaScript (parent scope):
  </p>
  
  <pre><code>$scope.myExpr = ...;
  </code></pre>
  
  <p>What should be in myExpr to use myCtrl as a controller via expression?</p>
  
  <p>I've tried <code>$controller('myCtrl')</code>... not working...</p>
  
  <p>P.S. If controller has been defined via globally accessible function.. it's possible to provide it as myExpr. But what to do if it has been defined so?</p>