0

Depending on the logic in services, I route to different views. To facilitate service injection, I use a loading controller to determine where to go next.

This works great, except that I can't go "back" through a loading controller. How do I either detect the back button, or fix my loading model to be more friendly to it?

 .when('/loading', { templateUrl: '/app/views/mystuff/loading.html', controller: 'LoadingController' }) angular.module('app').controller('LoadingController', ['$location', 'WhereService', function ($location, WhereService) { if (!WhereService.doneWithA()) { $location.path('/a'); } else if (!WhereService.doneWithB()) { $location.path('/b'); } else { location.href = "/myapp/somewhereelseentirely"//this is fine } }]); angular.module('app').controller('ALoadingController', ['$location', 'AService', function ($location, AService) { if (!AService.isDone()) { $location.path(AService.currentPath()); } else { $location.path('/');//triggers loading controller above } }]); 
1
  • If I understand correctly you cannot go back because pressing the back button would navigate you to the /loading route where the LoadingController takes over and navigates you back to the current view? If this is the case, doing $location.replace() before each $location.path('...') in the LoadingController may help. Commented Jul 27, 2015 at 14:04

1 Answer 1

2

Sounds like you need $location.replace():

If called, all changes to $location during current $digest will be replacing current history record, instead of adding new one.

https://docs.angularjs.org/api/ng/service/$location

Sign up to request clarification or add additional context in comments.

1 Comment

For any "loading" path, I added $location.replace() after each $location.path().

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.