angular-jsf-components
Version:
JSF Compliant Angular Components
43 lines (38 loc) • 1.26 kB
text/typescript
import {Component, ElementRef, EventEmitter, Input, Output,} from '@angular/core';
import {Router} from '@angular/router';
import {HFormService} from '../../services/h-form.service';
import {JsfElement} from '../../superclass/jsf-element';
({
selector: 'h-command-button',
templateUrl: './h-command-button.component.html',
styleUrls: ['./h-command-button.component.css'],
})
export class HCommandButtonComponent extends JsfElement {
('action')
route: string;
()
action = new EventEmitter<void>();
()
immediate = false;
()
value: string;
constructor(hFormService: HFormService, private router: Router,
elementRef: ElementRef) {
super(hFormService, elementRef);
}
async onClick() {
try {
await super.onClick();
if (this.immediate || await this.hFormService.validate()) {
// did we bind a route to this button or a custom action
if (this.route) {
await this.router.navigateByUrl(this.route);
} else {
this.action.emit();
}
}
} catch (e) {
console.error(e);
}
}
}