What is a service? How will you create a custom service

devquora
devquora

Posted On: Feb 22, 2018

 

The separation of concerns in AngularJS is achieved by using a service. A Service is a singleton javascript object and gets instantiated only once during an applications lifetime. Services provide some very useful methods essential to implement some powerful angular concepts.

For example $http service provides methods like GET, POST, PUT and DELETE which help to contact the server and help perform CRUD operations. Angular also provides the ability to create custom services. A service can be created in the below fashion in an angular application :


angular.module('myModule', []).factory('serviceId', function() {
var shinyNewServiceInstance;
return shinyNewServiceInstance;
});

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    AngularJS Basic Interview Questions

    What is AngularJS?

    AngularJS is a javascript framework which helps in developing web applications in MVC architectural pattern & SPA or..

    AngularJS Basic Interview Questions

    What are angular directives?

    Angular directives are the attributes which are decorated on the html tags or elements of an html page. Directives have ..

    AngularJS Basic Interview Questions

    What are custom directives?

    Angular provides the ability to create our own directives to implement our own custom templates or logic in our web appl..