I am loading the angular library and checking if the library isn't already included in the script.
<body>
<div ng-app="myApp">
{{1+1}}
</div>
<script type="text/javascript">
var angular;
// load angular library if undefined
if (typeof window.angular === 'undefined') {
var script_tag = document.createElement('script');
script_tag.type = 'text/javascript';
script_tag.src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js";
document.body.appendChild(script_tag);
console.log(script_tag, 'angular load');
} else {
console.log('script found');
}
</script>
//load angular script
<script type="text/javascript" src="widget-angular.js"></script>
</body>
And in the widget-angular.js:
var myApp = angular.module( 'myApp', []);
The error I am getting:
Uncaught TypeError: Cannot call method 'module' of undefined
First I thought that the cause of the error was because the angular library loaded after the widget script. But I have done various checks and it loads in good order. I have no idea why it doesn't recognise 'module'. If I call the library directly like this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
It works. But the result I need is that it checks if the library is already included. If not, than include the library script.
Thank you advance.