【问题标题】:Sending $_GET variables to templateUrl using ngRoute [duplicate]使用 ngRoute 将 $_GET 变量发送到 templateUrl [重复]
【发布时间】:2016-01-26 09:18:19
【问题描述】:

我目前正在将我的应用程序切换到单页应用程序。我在配置我的 ngRoute 时遇到了一些问题。 我想要的是使用 ?id=.

将 ID 发送到 templateUrl

我该怎么做? 这是我的代码:

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider
    .when('/testing/:id', {
        templateUrl: 'templates/testing.php?id=:id'
    });
}]);

它现在传递 ":id" 作为 ID 的值。这很明显,但是如何让它发送在 URL 中传递的“:id”?

例如:

/testing/45

变成:

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider
    .when('/testing/45', {
        templateUrl: 'templates/testing.php?id=45'
    });
}]);

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    根据$routeProvider documentationtemplateUrl也可以是一个函数:

    app.config(["$routeProvider", function($routeProvider) {
        $routeProvider
        .when('/testing/:id', {
            templateUrl: function(params) {
                return 'templates/testing.php?id=' + params.id;
            }
        });
    }]);
    

    【讨论】:

    • 它就像一个魅力。谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2019-02-01
    相关资源
    最近更新 更多