Using angular. injector with ngAnimate
I have included "ngAnimate" as a dependency on my ngApp.
Now in the jQuery file I am trying to access it using:
angular.injector(['ng', 'angular-sm']).invoke(['$compile', '$timeout' ,function ($compile, $timeout) {
But it gives me an error
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 they are NOT USED.
Then I tried:
var app_element = document.querySelector('[ng-app=angular-sm]');
angular.element(app_element).injector().invoke(['$compile', '$timeout' ,function($compile,$timeout) {
I took the ngApp injector and it worked. Why is that?
+3
Bhumi singhal
source
to share
1 answer
There is only one in Angular app $injector
and you can get it with
angular.injector('rootModule')
or
angular.element(document).injector()
In your case, it was not a root module, so you had an error.
+2
Tom craft
source
to share