title: make an angular app with js bookmarklet
body: <p>I'm trying to make an angularjs app out of an site by clicking on a JS bookmarklet.</p>
  
  <p>The problem is the ng-controller isn't recognize by angular and throws this error:</p>
  
  <pre>
  Error: Argument 'LDController' is not a function, got undefined
  </pre>
  
  <p>First i define ng-app and use angular.module with the same name, this works, i got <code>&lt;html ng-app="bookmarklet"&gt;</code>.
  Then I load an external file by the name of application.js. <code>app.controller('LDController', ..)</code> is defined in this file!</p>
  
  <p>What i am doing wrong? here is the js bookmarklet code:</p>
  
  <pre>
  function loadApp() {
    document.getElementsByTagName('html')[0].setAttribute('ng-app', 'bookmarklet');
  
    var div = document.createElement('div');
    div.setAttribute('ng-controller', 'LDController');
    div.innerHTML = '';
    document.body.appendChild(div);
  
    var js = document.createElement('script');
    js.innerText = "var app = angular.module('bookmarklet', []);";
    document.body.appendChild(js);
  
    js = document.createElement('script');
    js.setAttribute('src', 'http://example.org/js/application.js');
    document.body.appendChild(js);
  }
  
  (function () {
    if (typeof angular === 'undefined') {
      js = document.createElement('script');
      js.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js');
      js.onload = loadApp;
      document.body.appendChild(js);
    }
    else {
      loadApp();
    }
  }());
  </pre>