[英]angularjs ui-router come back to the current state
I am using angular ui-router
in my application. 我在应用程序中使用了角度
ui-router
。 I have a 2 states, create-app
and list-apps
. 我有两个状态,
create-app
和list-apps
。 When i create an app i transition to the state create-app
with param id
equal to null
. 当我创建一个应用程序时,我会转换为参数
id
等于null
的状态为create-app
。 The problem is that when i am on state create-app
i cannot transitionTo
create-app
. 问题是,当我处于状态
create-app
我无法transitionTo
create-app
。 The use case is that if in the middle of creating an app i want to create another app i have to transitionTo
create-app
but since the state is already create-app
ui-router does not change the state. 用例是,如果在创建应用程序的过程中我想创建另一个应用程序,我必须要
transitionTo
到create-app
但是由于状态已经是create-app
ui-router,因此不会更改状态。 I know this because i looked for firing of $stateChangeStart
and $stateChangeSuccess
event. 我知道这是因为我寻找了
$stateChangeStart
和$stateChangeSuccess
事件的触发。 None of these fire. 这些都不火。 But when i am on 'list-apps' or even
create-app
with param id
not equal to null
(which is edit app) i am able to come to state create-app
. 但是,当我在“列表应用”或什
create-app
具有参数id
不等于null
create-app
时(这是edit应用),我可以进入状态create-app
。
$scope.createApp = function() {
$state.transitionTo('create-app', {id: null});
};
SO i tried this 所以我尝试了这个
$scope.createApp = function() {
if ($state.current.name == 'create-app' && $state.params.id == null) { // when the state is create-app and not list-apps or edit-app
$state.current.name = '';
}
$state.transitionTo('create-app', {id: null});
};
In this when the state is create-app
and the i again try to come to the same state i change the state name to ''
and params to null
so angular finds the fromState
and toState
different . 在这种情况下,当状态为
create-app
且i再次尝试进入相同状态时,我将状态名称更改为''
并将params更改为null
以便angular发现fromState
和toState
不同。 Even this does not work. 即使这样也不起作用。 Is there some way i can do this?
有什么办法可以做到吗?
You can use $state.reload(). 您可以使用$ state.reload()。 There's a discussion on github about this here .
在github上有关于此的讨论。
Use it like this: 像这样使用它:
$state.reload();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.