【问题标题】:AngularJS: How to send parameter with $location.path()AngularJS:如何使用 $location.path() 发送参数
【发布时间】:2016-01-08 07:53:44
【问题描述】:

我正在尝试使用一些数字参数或参数在控制器中创建重定向调用,但我失败了。我正在使用此代码

$location.path('/tastlist/:$rootScope.job_id');

我也试过了

$location.path("/tastlist/",$rootScope.job_id');

我的路线如下:

$routeProvider.when('/tastlist/:job_id', {templateUrl: 'partials/list-task.html', controller: 'tasklistCtrl'});

Route 在我的 html 中运行良好,用于此代码:

<a ng-click="go('/tastlist/' + job.id)">back to task list</a>

我想通过在控制器中创建自动重定向 $location.path() 或通过任何其他方式。请帮我解决这个问题..

【问题讨论】:

    标签: javascript angularjs angularjs-directive location


    【解决方案1】:

    你的第二次尝试几乎是正确的

    $location.path("/tastlist/" + $rootScope.job_id);
    

    您正在使用要设置的实际值构建 url。 如果你愿意

     $location.path("/tastlist/4");
    

    $stateParams 中的job_id 将设置为 4

    【讨论】:

    • 谢谢兄弟。你赢得了我的尊重。它现在正在工作。别忘了也为我的问题点赞。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    相关资源
    最近更新 更多