i’m using Angularjs and I have a ng-view with some parts. The partial views have some scripts in the head.
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
...
</head>
<body>
<div class="section">
... some content
</div>
</body>
</html>
If i load a view those scripts are loaded too.
<div style="" class="ng-scope" ng-view="">
<meta class="ng-scope" charset="utf-8">
<script class="ng-scope" type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="section ng-scope">
.. some view content.
</div>
</div>
I’m using an HTML Editor for Twitter Bootstrap to edit views quickly and this tool needs the html, head and body tags. And I don’t want to remove them from templates. Is it posible to ignore the head tag of partial view when it’s loaded?
2
Answers
I got it. I took a look into templateRequestProvider and httpProvider. And Here is my solution.
It's not a best solution because it would filter each http request. Better to apply it only for ng-view. It should work with templateRequestProvider.httpOptions but only with angular 1.5+.
Instead of using a ng-view, isn’t better to create a directive with your template in, and use the compile() or in the link() phase to remove the bad tags ?
Afaik directives are the good way to alter the DOM.
I’m not really familiar with the compile() but I let you read this post if you are interested in : http://www.bennadel.com/blog/2794-when-do-you-need-to-compile-a-directive-in-angularjs.htm