I'm trying to make an angularjs app out of an site by clicking on a JS bookmarklet.
The problem is the ng-controller isn't recognize by angular and throws this error:
Error: Argument 'LDController' is not a function, got undefined
First i define ng-app and use angular.module with the same name, this works, i got <html ng-app="bookmarklet">.
Then I load an external file by the name of application.js. app.controller('LDController', ..) is defined in this file!
What i am doing wrong? here is the js bookmarklet code:
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();
}
}());
scripttags rather specially. Have you seen the discussion here where Igor talks about how the inclusion of jQuery could help? - Ram Rajamonyng-appdirective. The prescribed method for doing this is to NOT insertng-appand instead to callangular.bootstrapon the appropriate element after everything else is set up. So for instance: angular.element(document).ready(function() {angular.bootstrap(document, ['bookmarklet']);} Can you try this? There is more information here - Ram Rajamony