I am trying to make an angularjs application from a site by clicking on the JS booklet.
The problem is that the ng controller is not recognized by angular and throws this error:
Error: Argument 'LDController' is not a function, got undefined
First I define an ng application and use angular.module with the same name, this works, I got <html ng-app="bookmarklet"> . Then I upload an external file called application.js. app.controller('LDController', ..) is defined in this file!
What am I doing wrong? here is the js bookmark 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 ();
}
} ());
source share