# Frontend Service Usage Examples
## Auth Service
```typescript
import { Component, inject } from '@angular/core';
import { AuthService } from './services/auth.service';
@Component({
selector: 'app-header',
template: `
@if (authService.user(); as user) {
Welcome, {{ user.username }}!
@if (user.isAdmin) {
}
} @else {
}
`
})
export class HeaderComponent {
authService = inject(AuthService);
login() {
this.authService.login();
}
logout() {
this.authService.logout().subscribe();
}
}
```
## Games Service
```typescript
import { Component, OnInit, inject, signal } from '@angular/core';
import { GamesService } from './services/games.service';
import { AuthService } from './services/auth.service';
import { Game } from '@library/shared-types';
@Component({
selector: 'app-games',
template: `
My Games
@if (authService.isAdmin()) {
}
@for (game of games(); track game.id) {
{{ game.title }}
{{ game.platform }}
Status: {{ game.status }}
@if (authService.isAdmin()) {
}
}
`
})
export class GamesComponent implements OnInit {
gamesService = inject(GamesService);
authService = inject(AuthService);
games = signal([]);
showAddForm = false;
ngOnInit() {
this.loadGames();
}
loadGames() {
this.gamesService.getAllGames().subscribe(games => {
this.games.set(games);
});
}
deleteGame(id: string) {
if (confirm('Are you sure?')) {
this.gamesService.deleteGame(id).subscribe(() => {
this.loadGames();
});
}
}
editGame(game: Game) {
// Navigate to edit form or open modal
}
}
```
## Books Service
```typescript
// Similar pattern to games
import { BooksService } from './services/books.service';
// In component
booksService = inject(BooksService);
books = signal([]);
ngOnInit() {
this.booksService.getAllBooks().subscribe(books => {
this.books.set(books);
});
}
addBook(book: CreateBookDto) {
this.booksService.createBook(book).subscribe(() => {
this.loadBooks();
});
}
```
## Music Service
```typescript
// Similar pattern
import { MusicService } from './services/music.service';
musicService = inject(MusicService);
// Filter by type example
getAlbums() {
this.musicService.getAllMusic().subscribe(music => {
const albums = music.filter(m => m.type === 'album');
this.albums.set(albums);
});
}
```