açısal ve ui-yönlendirici
üzerinde Artış Ve ön şart yerine getirilmediği takdirde farklı bir duruma yönlendirme ile mücadele bir önleyici: (How do I preform a redirect in an angular interceptor).
Ama birisi $ stateChangeState ile işlem yapmanın daha uygun olacağını belirtti. Ama yine de sonsuz bir döngüye çalıştırıyorum:
/**
* Check here for preconditions of state transitions
*/
$rootScope.$on('$stateChangeStart', function(event, toState) {
// which states in accounts to be selected
var accountRequiredStates = ['user.list', 'user.new'];
if(_.contains(accountRequiredStates, toState.name)){
event.preventDefault();
ApiAccount.customGET('get_current').then(function(resp){
// if I have a selected account, go about your business
if(resp.hasOwnProperty('id')){
$state.go(toState.name);
} else { // prompt user to select account
$state.go('user.select_account');
}
})
}
});
Herkes daha iyi desen (işleri bir)
Teşekkür önerebilir!
Not: Burada Benzer sorun farklı bir yaklaşım: Ben bir uzman değilim gerçi bunu yapmak için çalışıyoruz genel bir şekilde yanlış bir şey, orada olduğunu sanmıyorum How do I preform a redirect in an angular interceptor
Sadece yeniden yönlendirmek istiyorsanız olayı önlemelisiniz. Sanırım $ state.go'nun bir '$ timeout' fonksiyonuna sarılması gerekiyor. – zeroflagL
teşekkürler - bir kod snipitini paylaşır mısınız? – Jonathan
Sorunun http://stackoverflow.com/questions/21631896/why-does-this-angular-ui-router-code-cause-an-infinite-loop-in-digest – linkary