angular-jsf-components
Version:
JSF Compliant Angular Components
40 lines (33 loc) • 1.23 kB
text/typescript
import {Component, ElementRef, Input, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs/Subscription';
import {ErrorMessage} from '../../objects/error-message';
import {HFormService} from '../../services/h-form.service';
import {MessageService} from '../../services/message.service';
import {JsfElement} from '../../superclass/jsf-element';
({
selector: 'h-message',
templateUrl: './h-message.component.html',
styleUrls: ['./h-message.component.css'],
})
export class HMessageComponent extends JsfElement implements OnInit, OnDestroy {
('for')
forId: string;
errorMessage = new ErrorMessage();
private subscription: Subscription;
constructor(hFormService: HFormService, private messageService: MessageService,
elementRef: ElementRef) {
super(hFormService, elementRef);
}
ngOnInit() {
this.subscription = this.messageService.subscribe(this.forId,
(value: ErrorMessage) => {
this.errorMessage = value;
});
}
ngOnDestroy() {
// in case we did not init at all
if (this.subscription) {
this.subscription.unsubscribe();
}
}
}