Service guides

Learn how reusable services handle models, HTTP, REST, realtime messages, routing, and browser storage.

A service is one reusable object or function that AngularTS can provide to controllers, components, directives, and other services. The act of requesting that service by name is called dependency injection.

Start with shared models, then choose the guide for the feature you need. Use the service reference when you already know a service token such as $http.


Models

Use app.model() to declare shared reactive application state as an injectable service.

Making HTTP requests with the $http service

Send requests with the $http service and configure defaults, transforms, interceptors, and XSRF behavior.

Decoupled Messaging

Use $eventBus for application-wide publish/subscribe messaging and scope events for scope-tree communication.

Real-Time Communication

Stream server events with $sse, exchange bidirectional messages with $websocket or $webTransport, and offload work with ng-worker and ng-wasm.

Typed REST Resources

Define typed REST endpoints once and use $rest for list, get, create, update, and delete flows backed by pluggable backends.

Client-Side Routing

Navigate between named states, read and modify the URL, manage history, and intercept route transitions.

Cookies And Browser Storage

Read and write cookies with $cookie, serialize objects, and use $window.localStorage or sessionStorage for client-side persistence.