Greetings I'm using angularjs in the front end but my web application is not a Single Page Application, it's a classic application where the browser makes a request to the server for each page that the user requests.
I want to abbreviate my code in each html page and build a master page using angularJS. I managed to abbreviate the <header>
, the menu and the <footer>
but I can not abbreviate the <head>
since when I put a directive ng-include
or a custom directive
everything I put in does not load on the page.
Because I have many tags <script>
of many javascript scripts that I have, and it is difficult every time I add a new script I have to add it in all the pages.
When I try to add an angular directive in the head tag, the content that should be added is not added.
<head ng-include="'/SpringMVCTemplateAnn/resources/angular/templates/seccionesMasterPage/head.html'">
this is the template where is the content that should go inside the head
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin 2 - Bootstrap Admin Theme</title>
<!-- Bootstrap Core CSS -->
<link href="/SpringMVCTemplateAnn/resources/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="/SpringMVCTemplateAnn/resources/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
<!-- Timeline CSS -->
<link href="/SpringMVCTemplateAnn/resources/dist/css/timeline.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="/SpringMVCTemplateAnn/resources/dist/css/sb-admin-2.css" rel="stylesheet">
<!--ESTILO PARA TABLAS SMART-->
<link href="/SpringMVCTemplateAnn/resources/angular/controladores/actividad/estilo.css" rel="stylesheet">
<!-- LIBRERIAS ANGULAR -->
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<script src="/SpringMVCTemplateAnn/resources/angular/app.js"></script>
<!--ANGULAR CONTROLADORES-->
<script src="/SpringMVCTemplateAnn/resources/angular/controladores/cliente/clienteController.js"></script>
<script src="/SpringMVCTemplateAnn/resources/angular/controladores/usuario/usuarioController.js"></script>
<!--ANGULAR RUTAS-->
<script src="/SpringMVCTemplateAnn/resources/angular/routes.js"></script>
<!--ANGULAR SERVICIOS-->
<script src="/SpringMVCTemplateAnn/resources/angular/servicios/cliente/clienteServicio.js"></script>
<script src="/SpringMVCTemplateAnn/resources/angular/servicios/usuarioServicios/usuarioServicio.js"></script>
EDIT
I would like to put the contents of my head in a separate file to be able to reuse it in all my pages, if I wanted to add something I only add it in the external file and so I do not have to modify each page, I already do this with my footer and I header but for some reason it does not work in the head
<!DOCTYPE html>
<html lang="en" ng-app="MyApp">
<head ng-include="mihead.html"> <--- aqui quisiera poner la ruta en donde se encuentre todo el contenido de mi head en un archivo aparte para poder reutilizarlo en todas las paginas
EDIT 2
It is possible to include my scripts at the end of the document using ng-include
example
This would be contained within the scriptsPartial.html file
<!--ANGULAR CONTROLADORES-->
<script src="/SpringMVCTemplateAnn/resources/angular/controladores/cliente/clienteController.js"></script>
<script src="/SpringMVCTemplateAnn/resources/angular/controladores/usuario/usuarioController.js"></script>
<!--ANGULAR RUTAS-->
<script src="/SpringMVCTemplateAnn/resources/angular/routes.js"></script>
<!--ANGULAR SERVICIOS-->
<script src="/SpringMVCTemplateAnn/resources/angular/servicios/cliente/clienteServicio.js"></script>
<script src="/SpringMVCTemplateAnn/resources/angular/servicios/usuarioServicios/usuarioServicio.js"></script>
How would you include this file using ng-include
since this would be a lot of scripts that are in the html but are not contained within an html tag as a div
. I could not do <div ng-include=""></div>
since this code would not make sense to enter it inside a div tag. Is it possible to use ng-include
to include html code in this case the declaration of my scripts without this ng-include
being inside a tag, or is it bad practice? Now that I think about it, it does not seem right to fill the head of so many scripts I prefer to put them at the bottom of the page with ng-include
. In which tag could I place my ng-include to introduce these scripts
EDIT 3
I added my ng-include in the following way but the scripts do not load. I can see that they are added to the page with the firefox console inspector, but if I check the network part they are not loaded. I can also see that they did not load because some elements of my page that depend on these scripts do not work.
<div ng-include="'/MyWebApp/resources/angular/templates/seccionesMasterPage/srciptsPartial.html'">
</div>
I also tried this way but it's the same
<ng-include
src="/MyWebApp/resources/angular/templates/seccionesMasterPage/srciptsPartial.html"
[onload="/MyWebApp/resources/angular/templates/seccionesMasterPage/srciptsPartial.html"]>
</ng-include>