jeudi 27 octobre 2016

How to add a new module dynamically?

Image that I have the following .js code:

 $.ajax({
     url: 'some/url',
     success: function(result) {
        $activeTabContainer.html(result);
    }
 });

The $activeTabContainer is jQuery selected div.

The result object contains html (with script tag), maybe something like:

<div ng-app="mySpa">
    <div ng-controller="myController"></div>
</div>

And later in the same .html file a script tag, which contains:

(function () {
    "use strict";
    var app = angular.module("mySpa", []);
    app.controller("myController", [function () {
        debugger;
    }]);
})();

It perfectly executes the .js part in the script tag, but I guess that angular must be somehow notified about the dynamically added module and its controllers, something like dynamically bootstrapping.

Do anyone have an idea?




Aucun commentaire:

Enregistrer un commentaire