I'm building a directive which changes a button's text while a condition remains true. For example while saving a from, until it is being processed, the text of the submit button should change to Saving...
and as the form submission finished, it should revert back to its original text.
Here is a what I'm trying:
import {Directive, ElementRef, Input, OnInit} from '@angular/core';
@Directive({
selector: '[LoadingText]'
})
export class LoadingTextDirective implements OnInit {
@Input('loadingTextValue') text: string;
@Input('loadingTextWhen') condition: boolean;
constructor(private elem: ElementRef) {}
ngOnInit() {
if (this.text && this.condition) {
this.elem.nativeElement.innerText = this.text;
}
}
}
Here is how I'm using it:
<button LoadingText loadingTextValue="Hold on! Saving..." [loadingTextWhen]="saving" type="button" (click)="onSave()">Save
</button>
saving: boolean = false;
I change saving
to true as onSave() function is called and false as it is finished.
How can I bind my directive condition Input to reflect according to the changes on saving
.?