कोणीय, और ui रूटर
पर अपेक्षाओं और एक अलग राज्य के लिए पुनः निर्देशित करता है, तो एक पूर्व शर्त को पूरा नहीं कर रहा है के साथ संघर्ष कर:
मैं उपयोग करने की कोशिश एक इंटरसेप्टर: (How do I preform a redirect in an angular interceptor)।
लेकिन किसी ने उल्लेख किया कि $ stateChangeState को संभालना अधिक उपयुक्त होगा। लेकिन मैं अभी भी एक अनंत लूप में चला रहा हूँ:
/**
* 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');
}
})
}
});
किसी को भी एक बेहतर पैटर्न (एक है कि काम करता है)
धन्यवाद सुझाव दे सकते हैं!
नोट: इसी समस्या अलग यहाँ दृष्टिकोण: How do I preform a redirect in an angular interceptor
यदि आप रीडायरेक्ट करना चाहते हैं तो आपको केवल ईवेंट को रोकना चाहिए। मुझे लगता है कि '$ state.go' को' $ टाइमआउट 'फ़ंक्शन में लपेटा जाना है। – zeroflagL
धन्यवाद - क्या आप एक कोड स्निपिट साझा कर सकते हैं? – Jonathan
मुझे लगता है कि आपका प्रश्न http://stackoverflow.com/questions/21631896/why-does-this-angular-ui-router-code-cause-an-infinite-loop-in-digest – linkary