Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMock - injector not attached to $rootElement #14022

Closed
jsuchenia opened this issue Feb 12, 2016 · 7 comments
Closed

ngMock - injector not attached to $rootElement #14022

jsuchenia opened this issue Feb 12, 2016 · 7 comments

Comments

@jsuchenia
Copy link

Under ngMock when injector was already created it's not connected to a $rootElement, so:
$rootElement.injector()`
returns an undefined value.

I wish to use $rootElement to create sub-elements for test purposes, then tested piece of code can use:
angular.element(localElement).injector()
to retrieve already initialised injector.

@jsuchenia
Copy link
Author

As a workaround I can add it to the rootNode by myself, but then I know internals of Angular:
$rootElement.data('$injector', $injector)

@gkalpak
Copy link
Member

gkalpak commented Feb 13, 2016

Hm...I submitted #14034, but tbh I am not sure why you need to call .injector() on elements.
Why can't you just inject the $injector (which is so meta and cool 😛 ) ?

@jsuchenia
Copy link
Author

@gkalpak My use case is similar to this one from an angular.injector documentation, so I have an angular app which is using separate framework for drawing in one of used directives (configured externally from JSON file, so I can't inject injector)
In some elements I wish to use data from other angular services, so I need instance of already initialised angular app, and it's working fine (except under ngMock tests)

@gkalpak
Copy link
Member

gkalpak commented Feb 14, 2016

Yeah, 3rd-party libs sound like a valid usecase.

gkalpak added a commit that referenced this issue Feb 16, 2016
gkalpak added a commit that referenced this issue Feb 16, 2016
@matsko
Copy link
Contributor

matsko commented Feb 21, 2016

@jsuchenia @gkalpak sorry guys to be the bearer of bad news but this fix causes a memory leak in Karma + JQuery (a particular internal Google projects was having an issue with this). Therefore we need to revert this for now until we can have a solution that doesn't use data() (or cause a leak). @gkalpak let's chat on Wednesday and figure out something better.

@matsko matsko reopened this Feb 21, 2016
@gkalpak
Copy link
Member

gkalpak commented Feb 21, 2016

#14098 fixes the leak. But if you need to revert it, go ahead and we'll figure it out later 😃

@gkalpak
Copy link
Member

gkalpak commented Feb 22, 2016

#14098 has neen merged. Relanded the fix along with appropriate meassures to prevent the leak.

Let's see if something breaks 😃

@gkalpak gkalpak closed this as completed Feb 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants