Since script can't be loaded inside templates, due to Angular's jQLite wasn't written to achieve it, I decided to add jQuery library before Angular since it checks for jQuery existence, and voila!, it works. But, the fact that I'm here asking a question, means that there's a 'but', so, the script doesn't execute before content loads. Of course, I made a little trick with routes.
In module's config section, I made this:
$routeProvider
.when("Business/:Context/:View?", {
templateUrl: function (url) {
return "Contexts/" + url.Context + "/" + (url.View || url.Context) + ".html";
}
});
Then let's say we set the route to
"#/Business/Test" he most locate a file called Test.hmtl on
"/Contexts/Test", right eh!. Let's say
Test.html content is this.
<script>
(function(ng){
console.log(ng)
ng.module('MyApp').controller('TestController', function ($scope, $route, $routeParams, $location, $http, $mdDialog) {
$scope.name = "TestController";
$scope.params = $routeParams;
$scope.name = "John";
});
})(angular)
</script>
Hola {{ name }}
And finally the real question: why is this happening? It's like the
<script> is executed after or I don't know, because, looking
the console[
^]:
Angular exists but the controller isn't added in time. Am I doing wrong? It this behavior allowed? Can anyone lead me in this trip?
What I have tried:
Explained above in question. There's nothing more to say.