<aura:application controller="echoController" extends="force:slds">
<lightning:button label="Toggle" variant="brand" onclick="{!c.showSpinner}"/>
<div class="exampleHolder">
<lightning:spinner aura:id="mySpinner" class="slds-hide"/>
</div>
</aura:application>
({
showSpinner: function (component, event, helper) {
helper.showSpinner(component);
var action = component.get('c.echo');
action.setCallback(this,function(response){
var state = response.getState();
if (state === "SUCCESS") {
helper.hideSpinner(component);
}
});
$A.enqueueAction(action);
}
})
({
showSpinner: function (component, event, helper) {
var spinner = component.find("mySpinner");
$A.util.removeClass(spinner, "slds-hide");
},
hideSpinner: function (component, event, helper) {
var spinner = component.find("mySpinner");
$A.util.addClass(spinner, "slds-hide");
}
})
public class echoController {
@AuraEnabled
public static String echo(String message) {
return message;
}
}
Thanks, its really cool and make it easy to use. Previously I had used gif image for the spinner.
ReplyDeleteI believe we can just do $A.util.toggleClass(spinner,'slds-hide') instead of adding and removing css class? I am speaking in terms of ease of use when copying and pasting :D
ReplyDelete