E
E
Ekaterina2014-10-09 22:59:53
Angular
Ekaterina, 2014-10-09 22:59:53

How to get reference to $compile in AngularJS outside of Angular instructions?

It so happened that I have nowhere to inject $compile. Those. there is a completely unrelated to angular code that receives the HTML containing the angular controller and I need to compile it. App already exists on the page.
How to correctly get a link to $compile?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-10-09
Protko @Fesor

So what's the point if you don't have an application with a controller? Without them, even if you take $compile, you can't really do anything. If it is, then angular.bootstrap

R
Ruslan Lopatin, 2014-10-10
@lorus

If the page already has an Angular application, then you can have an element with a controller with the necessary dependencies (including $compile) and methods for processing your data.
You can get this controller using an expression like angular.element(element).controller() . And you can do whatever you want with it.
And don't forget to call your controller via scope.$apply() if your calls will change the contents of the scope. The element's scope itself can be obtained in the same way as the controller.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question