Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

JavaScript
$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.

HTML
<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.
Posted
Updated 19-Jul-16 9:29am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900