1

I have this resource:

angular.module('showboardApp')
  .factory('Session', function () {
    return $resource('/api/session.json');
  });

I would like to access it from the chrome developer console. Is there some way to inject it and run immediately with similar syntax to this?

angular.module('showboardApp')
  .run(function(Session){
    var promise = Post.query();
    console.log(promise);
  });
justspamjustin
  • 1,730
  • 3
  • 19
  • 30

1 Answers1

3

What you basically need is your app's injector. Then you can use it to inject your service to a function and execute some code with it. E.g.:

var inj = angular.injector(['showboardApp']);
inj.invoke(function (Session) {...});
gkalpak
  • 47,844
  • 8
  • 105
  • 118
  • I get this error when trying to load my resource 'Person': Module 'Person' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. – Emanuele Paolini Jul 10 '14 at 16:12
  • @EmanuelePaolini: This is probably not what you want. If you want to gain access to the **same instance** of a service that your app is using, take a look at **[this answer](http://stackoverflow.com/questions/24595460/how-to-access-update-rootscope-from-outside-angular/24596251#answer-24596251)**. – gkalpak Jul 11 '14 at 08:20