I have got a simple example to try to figure out why my angular partial template can not load another javascript component.
I am using 1 template (singleArticleView.html) and a parent page(blog.html)and i am trying to apply run_prettify.js to a simple code snippet inside of my template. If the code is inside of the template it does not work. If i remove the code and the script tags from the child template and include them inside of the parent it works properly
How can I execute that javascript library inside my template? I think it does not work because DOM elements have loaded later.
How can I evaluate if the content in the partial template is already rendered in order to execute any external javascript code to manipulate the DOM?
I appreciate any suggestion
It is the code:
blog.html (Parent)
<script src="~/AngularJS/Controllers/articlesController.js"></script>
<script src="~/AngularJS/Controllers/singleArticleController.js"></script>
<div class="row">
<div class="col-md-8 col-md-offset-1">
<div data-ng-view>
</div>
</div>
</div>
singleArticleView.html (template)
<script src="~/Scripts/run_prettify.js"></script>
<link href="~/Content/prettify.css" rel="stylesheet" />
<div>
{{article.author }}
<pre class="prettyprint linenums lang-html">
<!DOCTYPE html>
<html>
<head>
<title>Demo | Prettify.JS</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
</pre>
</div>
singleArticleControlle.js (controller)
(function () {
var app = angular.module("dbayonaCode");
var singleArticleController = function ($scope, dataService, $window, $routeParams, $sce) {
$scope.article = {};
$scope.newComment = {};
//Get the article with its comments to show in the template and add a new comment
//It uses ArticlesController.cs
dataService.getArticleById($routeParams.id)
.then(function (data) {
//success
$scope.article = data;
$scope.myContent = $sce.trustAsHtml(data.body);
},
function () {
//error
$windows.location = "#/";
});
}
app.controller("singleArticleController", singleArticleController);
}());