Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in Web Technology by (47.6k points)

I have a service like:

angular.module('app').factory('ExampleService', function(){

this.f1 = function(world){

return 'Hello '+world; 

}

return this;

})

I would like to test it from the JavaScript console and call the function f1() of the service.

How can I do that?

1 Answer

+2 votes
by (106k points)

The one-liner solution is to use the below-mentioned command:

angular.element(document.body).injector().get('serviceName')

Another way would be to get the $scope of a particular element. After that select the element with the DOM inspection tool of your developer tools and then run the below mentioned line of code:-

angular.element($0).scope()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...