Tag: AngularJS services

22 Sep by vichu Tags: ,

#11 – Building a custom AngularJS Service

Reading Time: 3 minutesWe saw how to use AngularJS services through the use of some built-in AngularJS services. We will be using the ones previously mentioned extensively throughout the blog going forward, so don’t worry that we didn’t get to see them all in action yet. The core AngularJS services only touch the tip of the iceberg in […]
18 Sep by vichu Tags: , ,

Dependency Injection and in-built services

Reading Time: 9 minutesDependency Injection in AngularJS The entire service concept in AngularJS is heavily dependent on and driven by its Dependency Injection system. Any service known to AngularJS (internal or our own) can be simply injected into any other service, directive, or controller by stating it as a dependency. AngularJS will automatically figure out what the service […]
16 Sep by vichu Tags: , , , ,

AngularJS Services (Service VS Controllers)

Until now, we have dealt with data-binding in AngularJS. We have seen how to take data from our controllers and get it into the UI, and ensure that whenever the user interacts with or types in any data, we get it back into our controllers. We used and worked with some common directives, and dealt with forms and error handling. In this blog, we dive into AngularJS services. By the end of the next few blogs, we will have a thorough understanding of AngularJS services and get some hands-on experience in using core built-in AngularJS services. After that, we will learn why and when we should create AngularJS services, and actually create a simple service ourselves.

AngularJS Services

AngularJS services are functions or objects that can hold behavior or state across our application. Each AngularJS service is instantiated only once, so each part of our application gets access to the same instance of the AngularJS service. Repeated behavior, shared state, caches, factories, etc. are all functionality that can be implemented using AngularJS services. Let’s first take a look at why we need them.