AngularJS ui-router:reload:true也重新加载父状态

ps0*_*604 8 angularjs angular-ui-router

在这个插件中,你有两个ui-router状态,父母和孩子.通过单击链接调用子项时,由于它具有选项reload: true,因此始终会重新加载.这很好,但问题是父状态也被重新加载.尝试多次单击"填充11"链接,您将看到父时间戳也发生变化.

我怎样才能重新装载孩子?

使用Javascript:

var app = angular.module("app", ['ui.router']);

app.config(function($stateProvider, $urlRouterProvider) {

  $urlRouterProvider.otherwise("/");

  $stateProvider
    .state('state1', {
          templateUrl: 'state1.html',
          controller: function($scope) {

            $scope.theTime1 = Date.now();

          }
    })
    .state('state1.state11', {
          templateUrl: 'state11.html',
          controller: function($scope) {

               $scope.theTime11 = Date.now();

         }
    });

});
Run Code Online (Sandbox Code Playgroud)

Rea*_*lar 11

它实际上非常简单.

不要使用,reload因为这完全是你找到的.它重新加载路线的一切.

而是在子路径中添加一个参数,每次单击链接时都要确保更改该参数.这将迫使子状态重新加载.

我用一个例子更新了你的插件.我刚刚添加了一个num参数,并在count每次单击链接时增加一个变量.

http://plnkr.co/edit/qTA39rrYFYUegzuFbWnc?p=preview


Rad*_*ler 6

一个不断变化的参数作为马修福斯卡里尼建议,是(肯定)的路要走.可能还有另一种解决方案,即使用状态重新加载器的技术.下面,在这个更新的plunker中我们可以看到简化版本,但我们甚至可以在那里传递一些参数以使其更通用

.state('state1.reloader', {
      controller: function($state) {
        $state.go('state1.state11')
      }
})
Run Code Online (Sandbox Code Playgroud)

我们可以称之为:

// instead of this
<a href="#" ui-sref="state1.state11" ui-sref-opts="{reload: true}">
// we can do this
<a href="#" ui-sref="state1.reloader" >
Run Code Online (Sandbox Code Playgroud)

检查它在这里