Reputation: 2670
I need to show spinner only if data is not in the store (if ember sends request to the server)
Is there any way to do that?
Upvotes: 1
Views: 433
Reputation: 630
You can get the current state of models.
Your Controller:
savingObserver: function(){
this.set('showSpinner', this.get('model.isSaving'));
}.observes('model.isSaving')
If that is true, show spinner.
Or if you have multiple records to watch, do this:
savingObserver: function(){
this.set('showSpinner', this.get('content').isAny('isSaving', true);
}.observes('[email protected]')
Upvotes: 2
Reputation: 47367
save
returns a promise, you can infer it's started right before you've called save
and infer it's finished after the promise has resolved.
console.log('saving');
record.save().then(function(){
console.log('done saving');
}); // finally might be more appropriate in case it fails
You can also hook up to ajaxStart
and ajaxStop
and put a spinner there Showing a spinner during an AJAX request?
Upvotes: 1