Is it possible to reload only a view inside a state in AngularJS?

时间:2017-03-17 22:02:30

标签: javascript angularjs angular-ui-router reload

my problem is that I have two different views inside a AngularJS state, as seen beneath:

$stateProvider.state('root.base.persons', {
    url : 'persons/:id',
    views : {
        'level-1@root' : {
            templateUrl : 'html/person-level-1.html',
            controller : 'PersonLevel1Controller',
            controllerAs : 'personLevel1Ctrl'
        },
        'level-1-tabs@root' : {
            templateUrl : 'html/person-tabs.html',
            controller : 'PersonTabsController',
            controllerAs : 'personTabsCtrl'
        }
    },

Let's say the first view of the code above is a header in a webpage, and beneath it I have different views being loaded. I'm having a hard time discovering how can I refresh the content of the header when a refresh button that is placed in the header is clicked, without triggering the same reload in the "child" views/states beneath this parent state. I've tried $state.reload, $state.go and $state.transitionTo but I can't seem to find the answer to it.

Basically, is it possible in Angular to reload only a view inside a state?

Appreciate your time and answers. Regards

1 个答案:

答案 0 :(得分:0)

使用:

var options = { reload: true };
$state.go(to, params, options);
  

$ state.go选项

     

重新加载(v0.2.5) - {boolean=false|string|object},即使没有状态或参数更改,true也会强制转换。它将重新加载当前状态和父状态的结果和视图。如果reload是字符串(或状态对象),则获取状态对象(通过名称或对象引用);和\转换重新加载该匹配状态的解析和视图,以及它的所有子状态。

     

— UI-Router API Reference - $state.go options