角JS $ location.path(......)不触发路由控制器 [英] Angular JS $location.path(...) not firing route controller

查看:425
本文介绍了角JS $ location.path(......)不触发路由控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于角JS $ location.path(......)不触发路由控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆