Listenrefresh und Datashare-service eingebaut

This commit is contained in:
Hilmer, Carsten 2016-09-16 11:09:57 +02:00
parent 23beeb7e8c
commit 0d1b440b7d
4 changed files with 33 additions and 31 deletions

View File

@ -343,8 +343,7 @@ angular.module('starter', ['ionic','ngIOS9UIWebViewPatch','starter.controllers',
url: "/pokemonlist", url: "/pokemonlist",
cache: true, cache: true,
params:{ params:{
isAnimated:(ionic.Platform.isAndroid()==false), isAnimated:(ionic.Platform.isAndroid()==false)
controllersettings: null
}, },
views: { views: {
'menuContent': { 'menuContent': {

View File

@ -35,7 +35,7 @@
<p>&nbsp;Clear All Data</p> <p>&nbsp;Clear All Data</p>
</md-list-item> </md-list-item>
<md-list-item class="md-list-item-default" ng-click="navigateTo('app.pokemonlist', {isAnimated:false,controllersettings:{test:'Laola',refresh:'1'}})"> <md-list-item class="md-list-item-default" ng-click="refreshData()">
<i class="ion-android-refresh"></i> <i class="ion-android-refresh"></i>
<p>Refresh Data</p> <p>Refresh Data</p>

View File

@ -13,7 +13,7 @@
// http://ngcordova.com/docs/plugins/sqlite/ // http://ngcordova.com/docs/plugins/sqlite/
// //
// Controller of Pokemon List Page. // 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. // initialForm is the first activity in the controller.
// It will initial all variable data and let the function works when page load. // 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.initialForm();
}); });
$scope.$on('data_shared',function(){
$scope.$on('$ionicView.enter', function(viewInfo, state){ var data = dataShare.getData();
console.log('ENTERED'); if (data=='refresh'){
$scope.controllersettings = $stateParams.controllersettings; $scope.initialForm();
if ($scope.controllersettings.refresh=='1'){ console.log('refresched');
console.log("refreshed"); }
$scope.getPokemonList();
$timeout(function(){
$state.go('app.pokemonlist',
{
isAnimated:false,
controllersettings:
{
test:'Laola',
refresh:'0'
}
}
);
},400);
}
console.debug($scope.controllersettings);
}); });
});// End of Pokemon List Page Controller. });// End of Pokemon List Page Controller.
// Controller of pokemon Detail Page. // Controller of pokemon Detail Page.
@ -269,7 +256,7 @@ appControllers.controller('pokemonDetailCtrl', function ($mdBottomSheet, $mdToas
});// End Contract Detail page Controller. });// End Contract Detail page Controller.
// Controller of Contract Setting Page. // 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. // initialForm is the first activity in the controller.
// It will initial all variable data and let the function works when page load. // 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 };// End clear all data from sqlite
$scope.refreshData=function(){ $scope.refreshData=function(){
var data='refresh';
dataShare.sendData(data);
$scope.navigateTo('app.pokemonlist', {isAnimated:false});
}; };
// navigateTo is for navigate to other page // 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 //Next view animate will display in back direction
$ionicViewSwitcher.nextDirection('back'); $ionicViewSwitcher.nextDirection('back');
$state.go(stateName, { $state.go(stateName, {
isAnimated: objectData.isAnimated, isAnimated: objectData.isAnimated
controllersettings: objectData.controllersettings,
}); });
} }
}; // End of navigateTo. }; // End of navigateTo.

View File

@ -470,4 +470,20 @@ appServices.factory('pokedexDB', function ($cordovaSQLite)
}) })
},// End remove all data from sqlite. },// End remove all data from sqlite.
}; };
}); //End ContractDB service. });
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;
})