Last active
March 15, 2021 11:23
-
-
Save leifermendez/dda2d122fe00fdcfbc34ad2e66a2d220 to your computer and use it in GitHub Desktop.
loading-btn.directive.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Directive, ElementRef, Input, OnChanges, OnInit, Renderer2} from '@angular/core'; | |
@Directive({ | |
// tslint:disable-next-line:directive-selector | |
selector: '[ngxLoading]' | |
}) | |
export class LoadingBtnDirective implements OnInit, OnChanges { | |
@Input() textLoading: string; | |
@Input() textInitial: string; | |
@Input() disabled: boolean; | |
@Input() loadingFlag: boolean | undefined = undefined; | |
constructor(private elem: ElementRef) { | |
} | |
ngOnInit(): void { | |
} | |
ngOnChanges(changes): void { | |
if (changes.condition && changes.condition.currentValue) { | |
this.loadingFlag = changes.condition.currentValue; | |
} | |
this.elem.nativeElement.innerText = (this.loadingFlag) ? this.textLoading : this.textInitial; | |
if (![undefined].includes(this.loadingFlag)) { | |
this.elem.nativeElement.disabled = !!(this.disabled); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of use:
typescript
html
When

loading is false
When

loading is true