1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-09 12:03:33 +00:00

api form directive

This commit is contained in:
Kyle Spearrin
2018-01-31 00:10:14 -05:00
parent b50bf9d5cc
commit 619d3fd075
4 changed files with 43 additions and 16 deletions

View File

@@ -0,0 +1,32 @@
import {
Directive,
ElementRef,
Input,
OnChanges,
} from '@angular/core';
import { ValidationService } from '../services/validation.service';
@Directive({
selector: '[appApiForm]',
})
export class ApiFormDirective implements OnChanges {
@Input() appApiForm: Promise<any>;
constructor(private el: ElementRef, private validationService: ValidationService) { }
ngOnChanges(changes: any) {
if (this.appApiForm == null || this.appApiForm.then == null) {
return;
}
this.el.nativeElement.loading = true;
this.appApiForm.then((response: any) => {
this.el.nativeElement.loading = false;
}, (e: any) => {
this.el.nativeElement.loading = false;
this.validationService.showError(e);
});
}
}