javascript - angularjs: open a page then only loading data -
my current ionic code able data open page. however, want open page loading data. want change sequence since takes 10s load data.
here code:
$scope.opendetail = function (stock) { console.log(stock.symbol); $ionicloading.show(); //stockcondition if(stock.symbol.length<=$scope.stockcondition) { $stockdatafactory.getstockdetails(stock).then( function success(data) { $globalfactory.personalstockdata = data.details; $globalfactory.personalstocknews = data.news; $ionicloading.hide(); $state.go("app.page1"); }, function error(error) { alert(error.message); console.error(error); $ionicloading.hide(); } ); } else{//warrentcondition $stockdatafactory.getwarrentdetails(stock).then( function success(data) { $globalfactory.personalstockdata = data.details; $globalfactory.personalstocknews = {}; $ionicloading.hide(); $state.go("app.page1"); }, function error(error) { alert("stocks not found."); console.error(error); $ionicloading.hide(); } ); } };//end
in order open $state.go("app.page1");
first, loading data, how shall made changes of code?
you should show page1's html templet . approach using ng-if="personalstockdata" $settimeout() trick show data when it's loaded. looks
//page1 controller $stockdatafactory.getstockdetails(stock).then( function success(data) { $settimeout(function(){ $scope.personalstockdata = data.details; $scope.personalstocknews = data.news; }) }, function error(error) { alert(error.message); console.error(error); $ionicloading.hide(); } );
<div> ... <div ng-if="personalstockdata"> </div> <div ng-if="personalstocknews"> </div> ... </div>
anyways try not use global variables, hard track.
Comments
Post a Comment