javascript / beginner
Snippet
Defining an Injectable Service
Services are used to share logic or data across multiple components. The @Injectable decorator tells Angular this class can be part of the dependency injection system.
snippet.js
javascript
1
2
3
4
5
6
@Injectable({providedIn: 'root'})export class StorageService {save(data: any) { /* ... */ }}
angular
Breakdown
1
providedIn: 'root'
Makes the service available globally in the entire application.
2
@Injectable({
The decorator required to mark a class as an injectable service.