gpt4 book ai didi

javascript - ngRoute 传递参数不起作用

转载 作者:行者123 更新时间:2023-11-28 06:26:49 25 4
gpt4 key购买 nike

我在函数中传递 /?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()
}
}
}
});

最佳答案

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

或者$routeParams.search对象

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

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

关于javascript - ngRoute 传递参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35056419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com