What is service in angularjs with example?



What is service in angularjs with example?..

Answer / Saurabh Dixit

In AngularJS, a service is a JavaScript object that can be injected into other components to share data or functionality. Services provide a way to organize code and reuse it across different parts of the application. For example: nn```javascriptnapp.service('exampleService', function() {n this.examples = ['apple', 'banana', 'cherry'];nn return { getExamples: function() {n return this.examples;n }}n});```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

Why is typescript used in angular?

1 Answers  


Why there are two “destroy” events associated with the termination of scope in angularjs?

1 Answers  


What is angular cookie?

1 Answers  


What is angular?

1 Answers  


What is ng build?

1 Answers  


What is the difference between lazy loading and eager loading in angular 2?

1 Answers  


What is dependency injection in angularjs and how does it work?

1 Answers  


What is difference between $window and window in AngularJS?

1 Answers  


What are the difference between directive and component in angular 4?

1 Answers  


What is jQLite or jQuery lite?

1 Answers   Mind Tree,


Explain angularjs digest cycle?

1 Answers  


Does Angular use the jQuery library?

1 Answers  


Categories