ngRoute传递参数不起作用

时间:2016-01-28 08:34:52

标签: javascript angularjs ngroute

我正在我的函数中传递/?preview=true并且像这样捕获app.js $route.current.params.preview。但是当我在控制台日志中输出$route.current.params.preview时,它是未定义的。请帮我解决这个错误。

以下是blah.js 这样的http://localhost:9000/?preview=true

    var buildLangPathUrl = function () {
        return LANG_PATH ? LANG_PATH + '/' : '/';
    };

    this.openFrontPageWithPreview = function () {
        $rootScope.openPage(buildLangPathUrl() + '?preview=true');
    };     

app.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()
                } 
            }
        }
    });

1 个答案:

答案 0 :(得分:0)

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

$routeParams.search对象

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

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

相关问题