gpt4 book ai didi

angular-ui-router - Angular UI Router state.go参数在stateChangeStart中不可用

转载 作者:行者123 更新时间:2023-12-04 07:00:52 25 4
gpt4 key购买 nike

我正在使用Angular UI Router,我需要使用state.go方法发送参数。像这样:

$state.go('myState', { redirect : true });

我还需要在事件stateChangeStart中检查该参数。像这样:
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
//redirect parameter is not available here.
//should be in toParams right?
}

编辑:这是我的状态定义:
    $stateProvider.state('customer.search', {
url: '/search',
views: {
"right-flyover@": {
templateUrl: 'customer/search/search.tpl.html',
controller: 'CustomerSearchCtrl'
}
},
data: {
pageTitle: 'Sök användare',
hidden: true
}
});

最佳答案

ui-router将传递为状态层次结构定义的参数-我们正在导航至。请检查:

URL Parameters(引用:)

URL通常具有动态部分,称为参数。有几个用于指定参数的选项。基本参数如下所示:

$stateProvider
.state('contacts.detail', {
url: "/contacts/:contactId",
templateUrl: 'contacts.detail.html',
controller: function ($stateParams) {
// If we got here from a url of /contacts/42
expect($stateParams).toBe({contactId: 42});
}
})

因此,如果要使用param redirect,则状态应如下所示:
$stateProvider.state('customer.search', {
url: '/search/:redirect',
...
});

然后我们可以使用:
$state.go('customer.search', { redirect : true });

那将是 $statePrams的一部分

但是也许您尝试使用发送的选项,而不是参数:
  • $state.go(to [, toParams] [, options])(引用:)

  • 选项

    Object - If Object is passed, object is an options hash. The following options are supported:


  • location bool 值或“replace”(默认为true),如果为true,则将更新位置栏中的url,如果为false,则不会更新。如果字符串为“replace”,则将更新url并替换上一个历史记录。
  • 继承 bool 值(默认为true),如果为true,则将从当前url继承url参数。
  • relative stateObject(默认$ state。$ current),当使用相对路径(例如'^')转换时,定义要相对于哪个状态。
  • 通知 bool 值(默认为true),如果为true,则将广播$ stateChangeStart和$ stateChangeSuccess事件。
  • reload v0.2.5 bool 值(默认为false),如果为true,则即使状态或参数未更改也将强制转换,即重新加载相同状态。它与reloadOnSearch有所不同,因为如果要在所有条件都相同(包括搜索参数)相同的情况下强制重新加载,则可以使用它。

  • 那将是第三个参数(重新加载而不是重定向):
    $state.go('myState', null, { reload: true });

    关于angular-ui-router - Angular UI Router state.go参数在stateChangeStart中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25503236/

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