Adding a controller to a script tag when using angular $ compile

When the $compile-line binding of an angular HTML template, I try to add additional controllers and directives inside the tag<script> and use the ones contained in the HTML template.

Thus, I try to implement some kind of plug-in mechanism so that I can download external files that extend the functionality of my application.

The tag <script>really gets evaluated, but my problem is that compiling the HTML template takes place before evaluating JavaScript. Therefore, the compiler complains about the lack of controllers.


Example:

http://plnkr.co/edit/8oZYhRHAjP84ecnl6hG3?p=preview

In this example, an error occurs: Error: Argument 'Controller' is not a function, got undefined

If you delete lines 15-18 (HTML that refers to the created pipeline) in app.js, you can see in the console that creating this controller really works.

+2
source share
1 answer

I finally managed to do this based on the decision to dynamically load the AngularJS controller . thanks @JoseM, @MaximShoustin and @JussiKosunen for your tips and help.

http://plnkr.co/edit/fzmEZlP6bGBJqTOkfApH?p=preview

+1
source

All Articles