加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular-ui-router – 在StateChangeStart中不可用的Angular UI

发布时间:2020-12-17 07:30:35 所属栏目:安全 来源:网络整理
导读:我正在使用Angular UI路由器,我需要使用state.go方法发送参数.像这样: $state.go('myState',{ redirect : true }); 我还需要在事件stateChangeStart中检查该参数.像这样: $rootScope.$on('$stateChangeStart',function (event,toState,toParams,fromState,
我正在使用Angular UI路由器,我需要使用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?
}

编辑:这是我的statedefinition:

$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重定向,您的状态应如下所示:

$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布尔值或“替换”(默认为true),如果为true将更新位置栏中的URL,如果为false则不会.如果字符串“replace”,将更新url并替换上一个历史记录.
> inherit Boolean(默认为true),如果为true,则从当前url继承url参数.
> relative stateObject(默认$state.$current),当使用相对路径(例如’^’)进行转换时,定义哪个状态是相对的.
> notify Boolean(默认为true),如果为true将广播$stateChangeStart和$stateChangeSuccess事件.
> reload v0.2.5布尔值(默认值为false),则强制转换,即使状态或参数没有改变,也就是重新加载相同的状态.它与reloadOnSearch不同,因为当你想在一切都相同时强制重新加载时你会使用它,包括搜索参数.

那将是第三个参数(重新加载而不是重定向):

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读