Hi! I created a service to load the spinner in a div component, but it creates a little bit of duplicated code.
I tried to create a directive in angular to do the same thing on the div, but the spinner doesn't show. I debugged and the element and changes are working correctly.
Is there a way to implement the spinner as a directive??
This is the code of the directive:
import {Directive, ElementRef, Input, OnChanges, SimpleChanges} from "@angular/core";
import {createSpinner, hideSpinner, showSpinner} from '@syncfusion/ej2-angular-popups';
@Directive({
selector: '[scs-spinner]',
})
export class ScsSpinnerDirective implements OnChanges{
@Input() toggle: boolean;
constructor(private el: ElementRef) {
createSpinner({
target: el.nativeElement
});
}
ngOnChanges(changes: SimpleChanges) {
if(changes.toggle){
if(this.el.nativeElement)
changes.toggle.currentValue ?
setTimeout( () => showSpinner(this.el.nativeElement), 200) :
setTimeout( () => hideSpinner(this.el.nativeElement), 200);
}
}
}
<div id="detailContent" scs-spinner [toggle]="(loading$ |async) || (applying$ | async)" ></div>