Reputation: 23211
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 ?
Upvotes: 3
Views: 668
Reputation: 7078
Try this:
angular.injector(['ng', 'myServiceModule']).invoke(["myService", function(myService) {
//do something with myService
}]);
Upvotes: 3