I have a <script src=""> outside my ng-view, the script itself is a jQuery function that changes the content inside the ng-view, but it is not working unless I put the <script src=""> inside the html page I am rendering. This is fairly annoying and breaking the DRY rule (Don't repeat yourself) because I have to put said script in all of my html files now, since putting it at the bottom of my index.html is not working.
Here's my index.html
<!DOCTYPE html>
<html ng-app="enitoniApp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Stylesheets -->
<link rel="stylesheet" href="global.css">
<link rel="stylesheet" href="pages/css/home.css">
<!-- Fonts -->
<link href='http://fonts.googleapis.com/css?family=Roboto:400,300italic,300,100italic,100,400italic,500,500italic,700,700italic,900italic,900' rel='stylesheet' type='text/css'>
</head>
<body ng-controller="mainController">
...
<!-- Angular -->
<div class="wrap">
<div ng-view></div>
...
</body>
<!-- Javascripts -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="js/angular_script.js"></script>
<!--- Global Script -->
<script src="js/global.js"></script>
<!--- Content -->
<script src="js/contentinject.js"></script>
</html>
Note: "..." represents code that was too big and had to be taken out for this to be readable.
Now inside contentinject.js we have:
/** Content Injection **/
function isValid() {
$.getJSON("/js/content.json", function (d) {
console.log("json parsing of 'content.json' performed successfully.");
}).fail(function (d, textStatus, error) {
errorCall("Fatal error", "json", "Something went wrong and the site may not properly display, if the problem persists contact the website administrator.<br/><br/>Sorry about that.","<b>Couldn't parse 'content.json'</b><br/><br/>" + error)
});
}
setTimeout(isValid, 2000)
$.getJSON("/js/content.json", function (data) {
$(".lander .title").text(data.lTitle);
$(".lander .subtitle").text(data.lSubtitle);
$(".lander .text").html(data.lText.split('\n').join('<br />'));
});
Which modifies the DOM of:
home.html (What gets injected into ng-view, also our example partial)
<body>
<div class="lander">
<div class="w-ctrl">
<div class="container">
<div class="title-con">
<div class="title"></div>
<div class="subtitle"></div>
</div>
<div class="text-con">
<div class="text"></div>
</div>
</div>
</div>
</div>
</body>
Now as you can see, the script is CLEARLY at the bottom of the document, and also under angular.js, so it should load and inject the stuff into partial, but it isn't. If I put contentinject.js inside home.html, it works.
Is there any way around this?