angular-ui-router – 在StateChangeStart中不可用的Angular UI
我正在使用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并替换上一个历史记录. 那将是第三个参数(重新加载而不是重定向): $state.go('myState',null,{ reload: true }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |