javascript - Refreshing page on a back button in angular/ionic -


i trying refresh page on button new data article list. more specific have article list, , article page, on both of them have option of liking article. when user likes article on article page, if hits button icon on article list page won't refreshed new state. have tried making function on clicking button, , getting data again, icon doesn't change. data on console.log new data , value like=1 correct if user has liked article, icon doesn't change. code:

i articles in front page controller:

articleservice.all().then(function(data){     $scope.articles = data;   }) 

in article page html have button link:

<a ng-click="refresh()"></a> 

and in article list check value have , show icon according that:

<a ng-if="article.like == 1" ng-click="like(article)" class="subdued">               <img class="social-images" src="icons/heart.svg"/> lik             </a>             <a ng-if="article.like == 0" ng-click="like(article)" class="subdued">               <img class="social-images" src="icons/heart-outline.svg"/> lik             </a> 

this function in article controller:

$scope.refresh = function (){     return $state.go('main.front').then(function(state) {       articleservice.all().then(function(data){         $scope.articles = data;         console.log(data);       })     })   }; 

but since function in article controller cannot refresh data on front page. how can refresh data in front page controller page has different controller?

try 1 of these:

1.

 $scope.$on('$ionicview.beforeenter', function () {            $scope.refresh();         });  $scope.refresh = function (){         return $state.go('main.front').then(function(state) {           articleservice.all().then(function(data){             $scope.articles = data;             console.log(data);           })         })       }; 

2.

 $scope.$on('$tatechangesuccess', function () {            $scope.refresh();         }); 
  1. it may cache issue. add,
<ion-view cache-view="false" view-title="my title!">   </ion-view> 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -