diff --git a/www/js/app.js b/www/js/app.js index 2674d6a..6bdff46 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -343,8 +343,7 @@ angular.module('starter', ['ionic','ngIOS9UIWebViewPatch','starter.controllers', url: "/pokemonlist", cache: true, params:{ - isAnimated:(ionic.Platform.isAndroid()==false), - controllersettings: null + isAnimated:(ionic.Platform.isAndroid()==false) }, views: { 'menuContent': { diff --git a/www/templates/pokemonliste/html/pokemon-setting.html b/www/templates/pokemonliste/html/pokemon-setting.html index bbe78b6..cb93531 100644 --- a/www/templates/pokemonliste/html/pokemon-setting.html +++ b/www/templates/pokemonliste/html/pokemon-setting.html @@ -35,7 +35,7 @@

 Clear All Data

- +

Refresh Data

diff --git a/www/templates/pokemonliste/js/controllers.js b/www/templates/pokemonliste/js/controllers.js index f09f9ec..cf618dc 100644 --- a/www/templates/pokemonliste/js/controllers.js +++ b/www/templates/pokemonliste/js/controllers.js @@ -13,7 +13,7 @@ // http://ngcordova.com/docs/plugins/sqlite/ // // Controller of Pokemon List Page. -appControllers.controller('pokemonListCtrl', function ($scope, $stateParams,$ionicScrollDelegate, $filter, $mdDialog, $timeout, $ionicModal, $state, $mdBottomSheet, $ionicHistory,pokedexDB) { +appControllers.controller('pokemonListCtrl', function ($scope, $stateParams,$ionicScrollDelegate, $filter, $mdDialog, $timeout, $ionicModal, $state, $mdBottomSheet, $ionicHistory,pokedexDB, dataShare) { // initialForm is the first activity in the controller. // It will initial all variable data and let the function works when page load. @@ -94,29 +94,16 @@ appControllers.controller('pokemonListCtrl', function ($scope, $stateParams,$ion $scope.initialForm(); }); - - $scope.$on('$ionicView.enter', function(viewInfo, state){ - console.log('ENTERED'); - $scope.controllersettings = $stateParams.controllersettings; - if ($scope.controllersettings.refresh=='1'){ - console.log("refreshed"); - $scope.getPokemonList(); - $timeout(function(){ - $state.go('app.pokemonlist', - { - isAnimated:false, - controllersettings: - { - test:'Laola', - refresh:'0' - } - } - ); - },400); - } - console.debug($scope.controllersettings); + $scope.$on('data_shared',function(){ + var data = dataShare.getData(); + if (data=='refresh'){ + $scope.initialForm(); + console.log('refresched'); + } }); + + });// End of Pokemon List Page Controller. // Controller of pokemon Detail Page. @@ -269,7 +256,7 @@ appControllers.controller('pokemonDetailCtrl', function ($mdBottomSheet, $mdToas });// End Contract Detail page Controller. // Controller of Contract Setting Page. -appControllers.controller('pokemonSettingCtrl', function ($scope,$ionicViewSwitcher,$state, $timeout, $stateParams, $mdDialog, $mdBottomSheet, $mdToast, $ionicHistory, pokedexDB) { +appControllers.controller('pokemonSettingCtrl', function ($scope,$ionicViewSwitcher,$state, $timeout, $stateParams, $mdDialog, $mdBottomSheet, $mdToast, $ionicHistory, pokedexDB, dataShare) { // initialForm is the first activity in the controller. // It will initial all variable data and let the function works when page load. @@ -346,7 +333,9 @@ appControllers.controller('pokemonSettingCtrl', function ($scope,$ionicViewSwitc };// End clear all data from sqlite $scope.refreshData=function(){ - + var data='refresh'; + dataShare.sendData(data); + $scope.navigateTo('app.pokemonlist', {isAnimated:false}); }; // navigateTo is for navigate to other page @@ -363,10 +352,8 @@ appControllers.controller('pokemonSettingCtrl', function ($scope,$ionicViewSwitc //Next view animate will display in back direction $ionicViewSwitcher.nextDirection('back'); - $state.go(stateName, { - isAnimated: objectData.isAnimated, - controllersettings: objectData.controllersettings, + isAnimated: objectData.isAnimated }); } }; // End of navigateTo. diff --git a/www/templates/pokemonliste/js/services.js b/www/templates/pokemonliste/js/services.js index 4718ea8..ecc20df 100644 --- a/www/templates/pokemonliste/js/services.js +++ b/www/templates/pokemonliste/js/services.js @@ -470,4 +470,20 @@ appServices.factory('pokedexDB', function ($cordovaSQLite) }) },// End remove all data from sqlite. }; -}); //End ContractDB service. \ No newline at end of file +}); + +appServices.factory('dataShare', function ($rootScope,$timeout) +{ + var service = {}; + service.data = false; + service.sendData = function(data){ + this.data = data; + $timeout(function(){ + $rootScope.$broadcast('data_shared'); + },100); + }; + service.getData = function(){ + return this.data; + }; + return service; +}) \ No newline at end of file