Is there a way to dynamically adjust Angular's ui-routing based on certain data conditions? For instance, let's say we need to create a subscription process where the user is informed of whether their subscription was successful or not.
As the flow progresses, different decisions need to be made depending on the data. For example, if the user is already logged in, we need to prompt them for an email address to use for the subscription. If they are not logged in, they will see a login/registration screen instead.
After some research, I discovered that in Angular, a 'state' actually refers to a view, which initially led me down the wrong path when searching for help. I came across a similar situation on Stack Overflow (link) and also found this reference page, although I'm still unsure if it addresses my specific needs.
In essence, my question is: Can I dynamically change the view within a page using ui-router based on a data condition, such as:
/* this value could be set by an ng-init directive */
$scope.isLoggedOn = false;
...
function showView() {
if $scope.isLoggedOn --- > display the email view
if not $scope.isLoggedOn --- > display the login/registration view
};
* EDIT * In response to advice from Ran Sasportas, I have created a basic Plunker demo to showcase this functionality. It may be limited in features at the moment, but it does demonstrate how it works. You can view the demo here. I plan to test nesting views and controllers in the future for additional functionality.