问题描述
我已切换到 ui-router.一切都很顺利,除了一件事.在我的页面上,我有一个更改应用程序上下文的选择.无论如何,以前,当此上下文更改时,我正在执行此代码(特别是 set 方法):
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-router 后, $route.reload 什么也不做.我也没有在 ui-router 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?
推荐答案
好的,当我将 $state 注入控制器时它可以工作.
Ok it works when I inject $state into controller.
但是当像代码片段那样将它注入到服务中时,当然 $state 是未定义的.
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-router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!