$ route.reload()不能与UI的路由器工作 [英] $route.reload() does not work with ui-router
问题描述
我切换到以 UI路由器。一切都进行得很顺利,除了一件事。在我的网页我有一个选择,改变应用程序的情况下。不管怎么说,previously,在这样的背景下被改变,我在执行此code(尤其是设置方式):
I've switched to to ui-router. Everything went smoothly, except one thing. On my page I have a select that changes the context of the application. Anyway, previously, when this context was changed I was executing this code (in particular, set method):
'use strict';
angular.module('main').factory('lacContext', ['$route', function ($route) {
return {
set: function (id) {
sessionStorage.setItem("lac-context", id);
$route.reload();
},
get: function () {
return sessionStorage.getItem("lac-context");
}
};
}])
和
$route.reload()
在做最重要的事情。它重新加载页面。但切换到UI路由器后,$ route.reload什么都不做。我也没有发现与UI API路由器对应。如何解决这个问题?
was doing the most important thing. It reloaded the page. But after switching to ui-router, $route.reload does nothing. Also I did not find counterpart in ui-router API. How to solve this issue?
推荐答案
确定它的工作原理,当我注入$状态到控制器。
Ok it works when I inject $state into controller.
不过,当然$国家将其注入像code段服务时,是不确定的。
But when injecting it into service like code snippet, of course $state was undefined.
虽然
$state.go('.')
没有工作,我做了这样的事情:
did not work, I did something like this:
$stateProvider
.state('home', {
controller: function ($state) {
$state.go('advisoryLeadOffering.packages');
}
})
.state('advisoryLeadOffering.packages', {
url: "/packages",
templateUrl: "/AdvisoryLeadOffering/Packages",
controller: 'AdvisoryLeadOfferingPackages'
})
,当我需要重新加载我做这样的事情:
and when I need to reload I do something like this:
$state.transitionTo('home');
范围的方法内。
这篇关于$ route.reload()不能与UI的路由器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!