In this plunk你有两个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();
}
});
});
答案 0 :(得分:11)
实际上很简单。
请勿使用reload
,因为这与您找到的完全相同。它重新加载了路线的所有内容。
相反,在子路径中添加一个参数,每次单击链接时,请确保更改该参数。这将迫使子状态重新加载。
我用一个例子更新了你的插件。我刚刚添加了num
参数,并在每次点击链接时增加count
变量。
答案 1 :(得分:6)
更改参数建议为Mathew Foscarini,是(肯定)的方法。可能还有另一种解决方案,即使用状态重新加载器的技术。下面,在this updated plunker中我们可以看到简化版本,但我们甚至可以在那里传递一些参数以使其更通用
.state('state1.reloader', {
controller: function($state) {
$state.go('state1.state11')
}
})
我们可以这样称呼:
// instead of this
<a href="#" ui-sref="state1.state11" ui-sref-opts="{reload: true}">
// we can do this
<a href="#" ui-sref="state1.reloader" >
检查here