Hol*_*ley 323 angularjs angular-ui angular-ui-router
我正在使用Angular UI路由器,并希望重新加载当前状态并刷新所有数据/重新运行控制器以获取当前状态及其父级.
我有3个州级别:directory.organisations.details
directory.organisations包含一个包含组织列表的表.单击表中的项目会加载directory.organisations.details并使用$ StateParams传递项目的ID.因此,在详细信息状态中,我加载此项目的详细信息,编辑它们,然后保存数据.到目前为止都很好.
现在我需要重新加载此状态并刷新所有数据.
我试过了:
$state.transitionTo('directory.organisations');
Run Code Online (Sandbox Code Playgroud)
哪个进入父状态,但没有重新加载控制器,我想因为路径没有改变.理想情况下,我只想保留在directory.organisations.details状态并刷新父级中的所有数据.
我也尝试过:
$state.reload()
Run Code Online (Sandbox Code Playgroud)
我在API WIKI for $ state.reload上看过这个"(控制器现在重新修复的错误,很快就会修复)."
任何帮助,将不胜感激?
Roh*_*han 549
我发现这是用ui-router刷新的最短工作方式:
$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams
Run Code Online (Sandbox Code Playgroud)
更新版本:
$state.reload();
Run Code Online (Sandbox Code Playgroud)
这是别名:
$state.transitionTo($state.current, $stateParams, {
reload: true, inherit: false, notify: true
});
Run Code Online (Sandbox Code Playgroud)
文档:https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_reload
Hol*_*ley 152
此解决方案适用于AngularJS V.1.2.2:
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
Run Code Online (Sandbox Code Playgroud)
M K*_*M K 68
那将是最终的解决方案.(灵感来自@ Hollan_Risley的帖子)
'use strict';
angular.module('app')
.config(function($provide) {
$provide.decorator('$state', function($delegate, $stateParams) {
$delegate.forceReload = function() {
return $delegate.go($delegate.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});
};
return $delegate;
});
});
Run Code Online (Sandbox Code Playgroud)
现在,无论何时需要重新加载,只需调用:
$state.forceReload();
Run Code Online (Sandbox Code Playgroud)
Rou*_*ouR 57
用于离子骨架
$state.transitionTo($state.current, $state.$current.params, { reload: true, inherit: true, notify: true });//reload
$stateProvider.
state('home', {
url: '/',
cache: false, //required
Run Code Online (Sandbox Code Playgroud)
https://github.com/angular-ui/ui-router/issues/582
Vai*_*uri 45
可能更清洁的方法如下:
<a data-ui-sref="directory.organisations.details" data-ui-sref-opts="{reload: true}">Details State</a>
Run Code Online (Sandbox Code Playgroud)
我们只能从HTML重新加载状态.
Mut*_*pan 20
@Holland Risley的答案现在可以在最新的ui-router中作为api使用.
$state.reload();
Run Code Online (Sandbox Code Playgroud)
强制重新加载当前状态的方法.重新解析所有结算,重新安排控制器并重新触发事件.
http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state
Wes*_*ger 16
$state.go($state.current, $stateParams, {reload: true, inherit: false});
Run Code Online (Sandbox Code Playgroud)
小智 10
$scope.reloadstat = function () { $state.go($state.current, {}, {reload: true}); };
Run Code Online (Sandbox Code Playgroud)
如果您想重新加载整个页面,就像看起来一样,只需在控制器中注入$ window然后调用即可
$window.location.href = '/';
Run Code Online (Sandbox Code Playgroud)
但如果您只想重新加载当前视图,请注入$ scope,$ state和$ stateParams(后者以防万一您需要在即将到来的重新加载中更改某些参数,例如您的页码),然后在任何内容中调用控制器方法:
$stateParams.page = 1;
$state.reload();
Run Code Online (Sandbox Code Playgroud)
AngularJS v1.3.15 angular-ui-router v0.2.15
始终有效的愚蠢解决方法。
$state.go("otherState").then(function(){
$state.go("wantedState")
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
444565 次 |
| 最近记录: |