I'm new to angular, I'm trying to define module inside one of js files, and I felt that angular is processing my dom right away, where the var app = angular.module("myApp", []); will be defined at a later stage inside Shell or one of it's modules.
I tried with regular script tag but had errors, and I assumed if I inject this later once my dom is ready and then I instantiate modules inside Shell. please guide.
Javascript
document.addEventListener("DOMContentLoaded", function(event) {
inject();
new Shell();
});
function inject() {
var ng = document.createElement('script');
ng.src = "js/api/angular.js";
var scripts = document.getElementsByTagName('script')[0];
scripts.parentNode.insertBefore(ng, scripts);
}
inside Shell
var app = angular.module("myApp", []);
app.controller("MyController", function($scope) {
$scope.author = {
"name": "My name",
"title": "Developer",
"company": "my company"
}
});
my html is
<div id="result" ng-app="myApp">
<div ng-controller="MyController">
<h1>{{author.name}}</h1>
<p>{{author.title + ", " + author.company}}</p>
</div>
</div>
How should I address this that angular waits a bit before it lets me define my modules.