ng路由传递参数不起作用

ngRoute passing parameter does not work

本文关键字:参数 不起作用 路由 ng      更新时间:2023-09-26

我在函数中传递/?preview=true并在应用程序中捕获.js $route.current.params.preview就像那样。但是当我在控制台日志中输出$route.current.params.preview时,它是未定义的。请帮助我如何解决该错误。

下面是废话.js像这样http://localhost:9000/?preview=true

    var buildLangPathUrl = function () {
        return LANG_PATH ? LANG_PATH + '/' : '/';
    };
    this.openFrontPageWithPreview = function () {
        $rootScope.openPage(buildLangPathUrl() + '?preview=true');
    };     

应用.js

    $rootScope.$on('$routeChangeSuccess', function (user) {
        var path = $location.path();
        $rootScope.showIndex =
            path === LANG_PATH + '/';
        if ($rootScope.showIndex) {
            pageService.setPageMetaData('');
            if($rootScope.loggedUser) {
                console.log($route.current.params.preview); << 'undefined'
                if (!$route.current.params.preview) {
                    routeService.openSuggestedJobs()
                } 
            }
        }
    });

可以使用$location.search()作为查询参数对象的setter/getter。

$routeParams.search对象

if ($location.search().preview) {
// or
if ($routeParams.search) {

请务必注射您使用的任何一个