admin管理员组文章数量:1315252
in my view I have a ng-switch
like:
<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>
How can I make my Ionic Button refresh all ion-views.
Preferable in most just reevaluate a ng-switch
, in 1 reload EVERYTHING)
What I tried in my controller:
.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);
})
it would invalidate all caches I guess but it didn't work anyway :D
Note
- I searched but didn't find anything to do this..
- I don't want to mark my ion view with
cache=false
and opt out of all caching - I think this is ionic specific but it could be my general lack of knowledge concerning AngularJS :D
- the point is it works (without clearing the cache) when I next open the view again .. just that it isn't reloaded while looking at it
EDIT: I also tried with:
$ionicHistory.clearCache();
$state.go($state.current, {}, { reload: true });
or just
$state.go($state.current, {}, { reload: true });
NO LUCK
in my view I have a ng-switch
like:
<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>
How can I make my Ionic Button refresh all ion-views.
Preferable in most just reevaluate a ng-switch
, in 1 reload EVERYTHING)
What I tried in my controller:
.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);
})
it would invalidate all caches I guess but it didn't work anyway :D
Note
- I searched but didn't find anything to do this..
- I don't want to mark my ion view with
cache=false
and opt out of all caching - I think this is ionic specific but it could be my general lack of knowledge concerning AngularJS :D
- the point is it works (without clearing the cache) when I next open the view again .. just that it isn't reloaded while looking at it
EDIT: I also tried with:
$ionicHistory.clearCache();
$state.go($state.current, {}, { reload: true });
or just
$state.go($state.current, {}, { reload: true });
NO LUCK
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked May 17, 2015 at 19:17 Daij-DjanDaij-Djan 50.1k17 gold badges115 silver badges138 bronze badges 8- What's $ionicHistory? It's not clear what you are trying to do here – michelem Commented May 17, 2015 at 19:26
- ionicframework./docs/api/service/$ionicHistory – Daij-Djan Commented May 17, 2015 at 19:27
- I think this question is quite ionic specific but it could be my general lack of knowledge concerning angularjs :D – Daij-Djan Commented May 17, 2015 at 19:28
- I don't know ionic sorry – michelem Commented May 17, 2015 at 19:33
-
Did you mean to use
$ionicHistory.clearCache();
? If you don't have()
the method doesn't actually get called. – Jeremy Wilken Commented May 17, 2015 at 23:31
1 Answer
Reset to default 8 +75This doesn't seem to be ionic specific nor ng-switch
specific, but seems to be ui-router
specific. If I understand correctly, you want to refresh your view when you click your button and execute some data logic on Teams
. I see this here
$state.go($state.current);
However, this simply won't do it for you because since your path has not changed your controller will not re-run. However, $state.go()
offers additional parameters, including one we need for just this - reload
. Try the following...
$state.go($state.current, {}, { reload: true }); //second parameter is for $stateParams
This will refresh your views and re-run your controller, so you'll see this reflected in the UI. See $state.go(to [, toParams] [, options]) docs for more information
Furthermore, if you and others would like to see this in action I have crafted two simplistic examples. The code here is by no means best-practice driven, but is indeed self-descriptive enough to demonstrate the core issue and solution.
JSFiddle Example - working - using $state.go($state.current, {}, { reload: true });
JSFiddle Example - not working - using only $state.go($state.current);
本文标签:
版权声明:本文标题:javascript - How can I make my Ionic Button refresh all ion-views. (Preferable in most just revaluate a ng-switch) - Stack Overf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741971191a2407846.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论