src/app/alert/alert.component.ts
| selector | alert |
| templateUrl | alert.component.html |
Properties |
|
Methods |
constructor(alertService: AlertService)
|
||||||
|
Defined in src/app/alert/alert.component.ts:10
|
||||||
|
Parameters :
|
| ngOnDestroy |
ngOnDestroy()
|
|
Defined in src/app/alert/alert.component.ts:30
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Defined in src/app/alert/alert.component.ts:14
|
|
Returns :
void
|
| message |
Type : any
|
|
Defined in src/app/alert/alert.component.ts:10
|
| Private subscription |
Type : Subscription
|
|
Defined in src/app/alert/alert.component.ts:9
|
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { AlertService } from '../services/alert.service';
// tslint:disable-next-line: component-selector
@Component({ selector: 'alert', templateUrl: 'alert.component.html' })
export class AlertComponent implements OnInit, OnDestroy {
private subscription: Subscription;
message: any;
constructor(private alertService: AlertService) { }
ngOnInit() {
this.subscription = this.alertService.getAlert()
.subscribe(message => {
switch (message && message.type) {
case 'success':
message.cssClass = 'alert alert-success';
break;
case 'error':
message.cssClass = 'alert alert-danger';
break;
}
this.message = message;
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
<div *ngIf="message" [ngClass]="message.cssClass">{{message.text}}</div>