Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular-ui-router – 在StateChangeStart中不可用的Angular UI Router state.go参数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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])(引用:)

选项

> 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 });

大佬总结

以上是大佬教程为你收集整理的angular-ui-router – 在StateChangeStart中不可用的Angular UI Router state.go参数全部内容,希望文章能够帮你解决angular-ui-router – 在StateChangeStart中不可用的Angular UI Router state.go参数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。