All files / src/app/services carousel.service.ts

100% Statements 17/17
100% Branches 4/4
100% Functions 5/5
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x 1x             1x   163x           163x   163x 41550x 6213x                 1x 395x 7x             1x 32x   1x  
import { Injectable } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { Observable, Subject } from 'rxjs';
import { CarouselModel } from '../models';
 
/**
 * Carousel Service
 */
@Injectable()
export class CarouselService {
    /** collection of carousel */
    private readonly subject = new Subject<CarouselModel>();
 
    /**
     * constructor of CarouselService
     * @param router: Router
     */
    constructor(router: Router) {
        // clear carousel on route change
        router.events.subscribe(event => {
            if (event instanceof NavigationStart) {
                this.subject.next();
            }
        });
    }
 
    /**
     * init carousel
     * @param carouselModel: CarouselModel
     */
    init(carouselModel: CarouselModel): void {
        if (carouselModel) {
            this.subject.next(carouselModel);
        }
    }
 
    /**
     * get current carousel
     */
    getCarousel(): Observable<CarouselModel> {
        return this.subject.asObservable();
    }
}