I have included "ngAnimate" as a dependency to my ngApp.
Now in a jQuery file, I am trying to access this using :
angular.injector(['ng', 'angular-sm']).invoke(['$compile', '$timeout' ,function ($compile, $timeout) {
But this gives me an error of
Error: $injector:unpr
Unknown Provider
Unknown provider: $rootElementProvider <- $rootElement <- $animate <- $compile
And then I changed this to :
angular.injector(['ng','ngAnimate', 'angular-sm']).invoke(['$compile', '$timeout' ,function ($compile, $timeout) {
angular.injector(['ng','ngAnimate', 'angular-sm']).invoke(['$animate','$compile', '$timeout' ,function ($animate,$compile, $timeout) {
And these DIDN'T work either.
Then I tried:
var app_element = document.querySelector('[ng-app=angular-sm]');
angular.element(app_element).injector().invoke(['$compile', '$timeout' ,function($compile,$timeout) {
i.e I took the injector of the ngApp defined and it worked. Why so ?
There is only one $injector in an Angular application, and you can get it using
angular.injector('rootModule')
or
angular.element(document).injector()
In your case it wasn't the root module so you had an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With