我正在我的函数中传递/?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()
}
}
}
});
答案 0 :(得分:0)
可以使用$location.search()
作为查询参数对象的setter / getter。
或$routeParams.search
对象
if ($location.search().preview) {
// or
if ($routeParams.search) {
请务必注入您使用的任何一个