Spinner as Directive

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>

5 Replies 1 reply marked as answer

IS Indrajith Srinivasan Syncfusion Team June 10, 2020 12:20 PM UTC

Hi Cesar,

Greetings from Syncfusion support,

We have validated your reported query. We have to make the runnable application with the shared snippet. But we couldn't successfully create it.
 
 
 
Can you please replicate the issue in the above sample, so that we can validate and provide solution at earliest.

Regards,
 
Indrajith 



CS Cesar Smerling June 10, 2020 04:00 PM UTC

Hi,
Here I updated the example code to the changes.

In the init of component the loading value changes as observable, and the OnChanges of the directive receive that value but the spinner doesn't show or hide.

Thanks


IS Indrajith Srinivasan Syncfusion Team June 11, 2020 03:15 PM UTC

Hi Cesar,

Greetings from Syncfusion support,

We have validated your reported query. We have to make the runnable application with the shared snippet. But we couldn't successfully create it.
 
 
 
Can you please replicate the issue in the above sample, so that we can validate and provide solution at earliest.

Regards,
 
Indrajith 



CS Cesar Smerling June 12, 2020 11:50 AM UTC

Ok, I don't understand clearly.
There is the example not working. The Spinner doesn't show.

In the link you gave me I don't know how to save the changes.


IS Indrajith Srinivasan Syncfusion Team June 13, 2020 04:47 AM UTC

Hi Cesar,

Ignore our previous update,
 
 
We have validated on the reported query. The spinner is not shown, since the styles are not referred. We suggest you to refer the styles to load the spinner. We have also modified the sample shared.

 
Refer the below style in the index.html file: 
 
Style: <link rel='nofollow' href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet" /> 
 
Please let us know if the solution helps, 
 
Regards, 
Indrajith 


Marked as answer
Loader.
Up arrow icon