Angular JS $ location.path (...) does not start the route controller

So, I'm trying to update the path to submit the form with

$location.path('/search'); 

But it does not start the route registered in '/search' . I also tried with a trailing slash. Nothing, I also tried $scope.$apply , but I just got the error $apply already in progress , so there is definitely a scope.

Why not call the controller registered on the route, or load the templateUrl registered on it.

Router

 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/'); }; 

change

Adding this

 $scope.$on('$routeChangeStart', function(next, current) { $console.log('$routeChangeStart', arguments); }); 

Just before calling $location.path it is shown that the route does not begin to change. Is this a bug in Angular 1.2.5 ?

+6
source share
1 answer

So it turns out I really need to have ng-view somewhere on the page for the whole system to work.

It seems a little shy, but it works.

+3
source

All Articles