mirror of
https://github.com/bitwarden/browser
synced 2026-01-09 12:03:33 +00:00
api form directive
This commit is contained in:
32
src/app/directives/api-form.directive.ts
Normal file
32
src/app/directives/api-form.directive.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user