ngRoute 传递参数不起作用
ngRoute passing parameter does not work
我在我的函数中传递 /?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) {
请务必注入您使用的任何一个
我在我的函数中传递 /?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) {
请务必注入您使用的任何一个