3

i have an angular service. this is the code :

angular.module('myServiceModule', [])
    .service('angService',function({
     this.get=function(){
        console.log('i am accessible');
     }
});

i have to access get() method of angular service in javascript code(not from angular code).

<script>
  function caller(){
    //here i have to access service get() method.how is it possible.
    //can i do this->
    myServiceModule.get();
  }
 caller();//this function i am calling after service load.
</script>

i have done this. but it is not right. How is it possible ?

2
  • Do you need the same service instance the angular app is using? Commented Apr 12, 2015 at 0:14
  • yes, and i got the solution by @Mosho Commented Apr 12, 2015 at 0:36

1 Answer 1

3

Try this:

angular.injector(['ng', 'myServiceModule']).invoke(["myService", function(myService) {
    //do something with myService
}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.