-import { TestBed, getTestBed } from '@angular/core/testing';
+import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { VorgangService } from './vorgang.service';
-import { Vorgang } from './vorgang';
describe('VorgangService', () => {
let service: VorgangService;
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of, EMPTY } from 'rxjs';
-import { catchError, tap } from 'rxjs/operators';
+import { catchError, map, tap } from 'rxjs/operators';
+import { select, Store } from '@ngrx/store';
import { Vorgang } from './vorgang';
+import { State } from './reducers/vorgang';
@Injectable({
})
};
- constructor(private http: HttpClient) { }
+ constructor(
+ private http: HttpClient,
+ private store: Store<{ vorgang: State }>) { }
/** POST: Einen neuen Vorgang erzeugen */
create(vorgang: Vorgang): Observable<Vorgang> {
return this.gpsUrl + vbId + '/save';
}
+ Observable<number> observe() {
+ return this.store.pipe(select('vorgang'), map(vorgang => vorgang.counter));
+ }
+
/**
* Handle Http operation that failed.
* Let the app continue.
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
-import { Store, select } from '@ngrx/store';
+import { Store } from '@ngrx/store';
import { increment, decrement, reset } from '../actions/vorgang';
-import { map } from 'rxjs/operators';
+import { VorgangService } from '../vorgang.service';
import { State } from '../reducers';
@Component({
vorgang$: Observable<number>;
- constructor(private store: Store<{ vorgang: State }>) {
- this.vorgang$ = store.pipe(select('vorgang'), map(vorgang => vorgang.counter));
+ constructor(
+ private store: Store<{ vorgang: State }>,
+ private service: VorgangService) {
+ this.vorgang$ = service.observe();
}
ngOnInit(): void {