all files / src/app/components/alert/ alert.component.ts

100% Statements 10/10
100% Branches 2/2
100% Functions 4/4
100% Lines 8/8
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 44 45                                       34×             34×   25×               34× 33×        
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { AlertService } from '../../services';
 
/**
 * Alert Component
 */
@Component({
    selector: 'app-alert',
    templateUrl: 'alert.component.html'
})
 
export class AlertComponent implements OnDestroy, OnInit {
    /** message object */
    message: any;
    /** subscription */
    subscription: Subscription | undefined;
 
    /**
     * constructor of AlertComponent
     * @param alertService: AlertService
     */
    constructor(public alertService: AlertService) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.subscription = this.alertService.getMessage()
            .subscribe(message => {
                this.message = message;
            });
    }
 
    /**
     * ngOnDestroy
     */
    ngOnDestroy(): void {
        if (this.subscription !== undefined) {
            this.subscription.unsubscribe();
        }
    }
}