Friday, May 15, 2015

Angular JS Service Contents

I was stumbling around the other day trying to figure out what a value was on my service during a call.  Eventually I found that you can get any injected service as long as you have the scope it was injected into.  Since we already know you can get scope in the Chrome console by selecting an item, I mashed those two things up and got this:

angular.element('[ng-controller="homeController"]').injector().get('homeService')

That gets me the service that was injected as "homeService" into whatever element has the ng-controller of "homeController".

The only hitch with this one is (I think) you have to have jQuery included in order for this particular selector to work.

No comments:

Post a Comment