在我看来,我有一个这样的ng-switch
:
<div ng-switch on="team.isFavorite">
<button class="button button-energized snbutton" ng-switch-when="false" ng-click="makeTeamFavorite()">
Show team on dashboard
</button>
<p class="snmsg" ng-switch-default>
This team is shown on the dashboard
</p>
</div>
如何让我的离子按钮刷新所有离子视图。
最好在大多数情况下只重新评估一个ng-switch
,在1个中重新加载所有内容)
我在控制器中所做的尝试:
.controller('List-PeopleCtrl', function($ionicHistory, $state, $scope, $stateParams, Teams) {
$scope.makeTeamFavorite = function() {
Teams.setFavoriteId($stateParams.teamId);
$ionicHistory.clearCache();
$state.go($state.current);
}
$scope.team = Teams.get($stateParams.teamId);
$scope.team.isFavorite = Teams.getFavoriteId()==$stateParams.teamId;
$scope.people = Teams.members($stateParams.teamId);
})
我猜它会使所有缓存失效,但无论如何它都不起作用:D
备注
cache=false
标记我的ion视图,并选择退出所有缓存时没有重新加载
编辑:我也尝试过:
$ionicHistory.clearCache();
$state.go($state.current, {}, { reload: true });
或者只是
$state.go($state.current, {}, { reload: true });
不走运
发布于 2015-05-21 02:59:09
这似乎不是离子特定的,也不是ng-switch
特定的,但似乎是ui-router
特定的。如果我理解正确的话,您希望在单击按钮并在Teams
上执行一些数据逻辑时刷新视图。我在这里看到这个
$state.go($state.current);
但是,这根本不会为您做这件事,因为由于您的路径没有更改,您的控制器不会重新运行。然而,$state.go()
提供了额外的参数,包括我们需要的一个参数- reload
。尝试执行以下操作...
$state.go($state.current, {}, { reload: true }); //second parameter is for $stateParams
这将刷新视图并重新运行控制器,因此您将在UI中看到这一点。有关详细信息,请参阅$state.go(to [, toParams] [, options])文档
此外,如果您和其他人希望看到这一点,我精心制作了两个简单的示例。这里的代码绝不是最佳实践驱动的,但确实是自描述的,足以演示核心问题和解决方案。
JSFiddle Example -工作-使用$state.go($state.current, {}, { reload: true });
JSFiddle Example -不工作-仅使用$state.go($state.current);
https://stackoverflow.com/questions/30291090
复制相似问题