角JS $ location.path(......)不触发路由控制器路由、控制器、JS、location

由网友(把心弄丢了)分享简介:所以我想利用提交以更新的形式路径So I'm trying to update the path on form submit using$location.path('/search');但它不触发注册到路径'/搜索我以斜线尝试过。没什么,我也试过 $范围。$适用,但我刚刚得到的 $已经在进行中适用这样的错误有绝...

所以我想利用提交以更新的形式路径

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.

为什么不叫这个注册到路由的控制器或加载 templateUrl 注册吧。

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-提交回调

$scope.doSearchRequest = function (event, params) {
    // Prevent the default action
    event.preventDefault();
    $scope.data = params;

    $location.path('/search/');
};

修改

添加此

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

之前的 $ location.path 来电显示,路线不开始改变。这是一个bug 角1.2.5

Just before the $location.path call shows that the route doesn't start to change. Is this a bug in Angular 1.2.5?

推荐答案

因此​​,原来我确实需要有一个 NG-视图某处整个页面上系统正常工作。

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.

阅读全文

相关推荐

最新文章