So I'm trying to update the path on form submit using
$location.path('/search');
But it isn't triggering the route registered to '/search' I've tried with a trailing slash too. Nothing, I've also tried $scope.$apply but I just get the $apply already in progress error so there's definitely a scope.
Why wouldn't this call the controller registered to the route or load the templateUrl registered to it.
App.config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true).hashPrefix('!');
    $routeProvider
        .when("/", {
                "controller"  : "HomeController",
                "templateUrl" : "templates/home.html"
        })
        .when("/search", {
                "controller"  : "SearchResultsController",
                "templateUrl" : "templates/search-results.html"
        })
        .when("/search/:location", {
                "controller"  : "SearchLocationController",
                "templateUrl" : "templates/search-results.html"
        })
        .otherwise({
                "redirect" : "/"
        });
});
ng-submit callback$scope.doSearchRequest = function (event, params) {
    // Prevent the default action
    event.preventDefault();
    $scope.data = params;
    $location.path('/search/');
};
edit
Adding this
$scope.$on('$routeChangeStart', function(next, current) { 
           $console.log('$routeChangeStart', arguments);
        });
Just before the $location.path call shows that the route doesn't start to change. Is this a bug in Angular 1.2.5?
So it turns out I actually needed to have an ng-view somewhere on the page for the whole system to work.
Seems a bit screwy but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With