第18篇:ui-router强制刷新当前路由

来源:互联网 发布:悬疑小说 知乎 编辑:程序博客网 时间:2024/06/09 02:11

在使用ui-router的项目中当编辑某个栏目完成之后需要重新加载,或者当输入信息有误需要恢复初始的表单状态时,就需要对当前路由进行强制刷新,在angular1.4版本中使用$state.reload()或者$state.reload('currentState')并没有起到作用,尝试使用$state.transitionTo()起到了作用。

1.直接在代码中使用:

$state.transitionTo($state.current, $stateParams, {    reload: true,    inherit: false,    notify: true});

2.在config中配置,在代码中直接调用

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;    });});
调用:

$state.forceReload();


参考来源:https://stackoverflow.com/questions/21714655/reloading-current-state-refresh-data