0
Hello, I’m starting in Angular Js, and I’m doing a project in Single Page Application, in my index, I load some scripts and my ng-view, but in one of my partials, I need to load a script in it, it doesn’t make sense to directly load into the index, because I need DOM elements that are in my view, and it would be an unnecessary upload as not all users will get to this view. But I realized that the scripts within partials are not executed. Someone could give me a help, follow my index, main and partial codes. Thank you.
Index.html
<html lang="pt-br" ng-app="sistema">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Index.html</title>
<script src="/js/lib/angular.min.js"></script>
<script src="/js/lib/angular-route.min.js"></script>
<script src="/js/lib/angular-resource.min.js"></script>
<script src="js/main.js"></script>
<link href="/css/style.min.css" rel="stylesheet" />
<script src="/js/lib/jquery.min.js"></script>
</head>
<body>
<ng-view></ng-view>
</body>
</html>
Partial html.
<script src="caminho-do-meu-script.js"></script>
<script>
$(document).ready(function(){
alert("aqui meu script inline");
});
</script>
<h1>Minha partial com scripts</h1>
Main.js
angular.module('sistema', ['ngRoute', 'ngResource'])
.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when('/teste', {
templateUrl: 'partials/partial.html'
});
$routeProvider.otherwise({redirectTo: '/teste'});
});
Man, I was really looking for something like the Lazyload that responded down here. But in case I needed it here, putting the script in the controller solves my problem, thank you very much!
– Aldo Fernandes Junior
Glad you could solve your problem. Hugs.
– João Silva