2016-09-26 2 views
0

은 모델을 저장할 때 템플릿로드를 표시하는 방법입니다.Ember loader on model 저장

다른 경로로 전환 할 때 응용 프로그램 수준로드 템플릿을 사용할 수 있지만로드 템플릿이 표시되지 않을 때 모델을 저장할 때 사용할 수 있습니다.

this.transitionTo ('routeName')는 서버에서 promise를 얻을 때까지 load.hbs로 이동하지만 model.save()를 실행하면 표시되지 않습니다.

+0

로딩 부 상태 것 'beforeModel,'model' 또는'afterModel'이 약속을 되 돌렸을 때만 보여줄 것입니다. 모델 저장 중에 무언가를 보여주고 싶다면 커스텀 로더를 보여줘야합니다 –

답변

1

loading and error substates은 경로를로드 할 때만 사용됩니다. 컨트롤러 액션 중에 액션을 호출 할 방법이 없습니다 (액션이 새로운 경로를로드하지 않는 한, 그 상태는 여전히 액션이 아니라 새로운 경로를로드하는 것과 관련됩니다). 특성 및 일부를 사용하여 동작을 수행 할 때

여전히 로딩 템플릿을 표시 할 수

템플릿 :

<!-- templates/components/user-account.hbs --> 
{{#if busy}} 
    {{partial 'loading-template-name'}} 
{{else}} 
    {{!-- template content --}} 
    <button {{action "save"}}>Save</button> 
{{/if}} 

성분 :

// components/user-account.js 
import Ember from 'ember'; 

export default Ember.Component.extend({ 
    actions: { 
    save: function() { 
     if (this.get('busy')) { 
     return; 
     } 

     this.get('user').save() 
     .then(() => { 
     // handle success 
     }) 
     .catch((e) => { 
     // handle error 
     }) 
     .finally(() => { 
     this.set('busy', false); 
     }); 
    }, 
    }, 
}) 
관련 문제