mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-13 22:33:03 -05:00
feat(doc): move di
This commit is contained in:
29
apps/angular/di/src/app/currency.service.ts
Normal file
29
apps/angular/di/src/app/currency.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ComponentStore } from '@ngrx/component-store';
|
||||
import { map } from 'rxjs';
|
||||
|
||||
export interface Currency {
|
||||
name: string;
|
||||
code: string;
|
||||
symbol: string;
|
||||
}
|
||||
|
||||
export const currency: Currency[] = [
|
||||
{ name: 'Euro', code: 'EUR', symbol: '€' },
|
||||
{ name: 'Dollar US', code: 'USD', symbol: 'US$' },
|
||||
{ name: 'Dollar Autralien', code: 'AUD', symbol: 'AU$' },
|
||||
{ name: 'Livre Sterling', code: 'GBP', symbol: '£' },
|
||||
{ name: 'Dollar Canadien', code: 'CAD', symbol: 'CAD' },
|
||||
];
|
||||
|
||||
@Injectable()
|
||||
export class CurrencyService extends ComponentStore<{ code: string }> {
|
||||
readonly code$ = this.select((state) => state.code);
|
||||
readonly symbol$ = this.code$.pipe(
|
||||
map((code) => currency.find((c) => c.code === code)?.symbol ?? code)
|
||||
);
|
||||
|
||||
constructor() {
|
||||
super({ code: 'EUR' });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user