How can I refresh a view in Ionic and AngularJS to display the updated data -


i have made simple app using ionic , angularjs takes values 1 view, stores data sqlite database , displays added values in view. have made use of ion-tabs displaying views. when switch view after adding items, unable see added value. need close app , launch again see updated list.

is there way can reload view when switch it?

html

  <ion-tabs class="tabs-icon-top tabs-positive">     <ion-tab title="home" icon="ion-home" ui-sref=".home">       <ion-nav-view name="tab-home">       </ion-nav-view>     </ion-tab >     <ion-tab title="add item" icon="ion-plus-round" ui-sref=".additem">       <ion-nav-view name="tab-item"></ion-nav-view>     </ion-tab>     <ion-tab title="view items" icon="ion-navicon-round" ui-sref=".viewitems">       <ion-nav-view name="tab-viewitems"></ion-nav-view>     </ion-tab>   </ion-tabs> 

js

 .state('addlist.viewitems', {       url: '/viewitems',       reload:true,       views:{         'tab-viewitems':{           templateurl: 'templates/viewitems.html',           controller: 'examplecontroller',         }       }     }) 

i have added 'reload:true' inside state still doesn't work. :( please help. in advance :)

controller

var example=angular.module('starter', ['ionic', 'ngcordova']);  example.controller("examplecontroller", function($scope, $cordovasqlite, $state, $ionicpopup)   $scope.enter = function (purchasetype, stonename, size, weight, pieces, color, shape, salesprice) {     var query = "insert items_list (purchasetype,stonename,size,weight,pieces,color,shape,,salesprice) values (?,?,?,?,?,?,?,?)";     $cordovasqlite.execute(db, query, [purchasetype, stonename, size, weight, pieces, color, shape, salesprice]).then(function (res) {       var alertpopup = $ionicpopup.alert({         title: 'successful!',         template: 'record entered!'       });     }, function (err) {       console.log(err);       window.alert(err);       });   }; 

you can try using $scope.$apply(); @ end of insert function in same controller.

the other solution below.

make tabs setup:

 <ion-tabs class="tabs-icon-top tabs-positive">     <ion-tab title="home" icon="ion-home" ng-controller="homectrl" ui-sref=".home">         <ion-nav-view name="tab-home">         </ion-nav-view>     </ion-tab >     <ion-tab title="add item" icon="ion-plus-round" ng-controller="additemctrl" ui-sref=".additem">         <ion-nav-view name="tab-item"></ion-nav-view>     </ion-tab>     <ion-tab title="view items" icon="ion-navicon-round" ng-controller="viewitemsctrl" ui-sref=".viewitems">         <ion-nav-view name="tab-viewitems"></ion-nav-view>     </ion-tab> </ion-tabs> 

controllers:

 example.controller("additemctrl", function($scope, $cordovasqlite, $state, $ionicpopup) { $scope.enter = function (purchasetype, stonename, size, weight, pieces, color, shape, salesprice) {     var query = "insert items_list (purchasetype,stonename,size,weight,pieces,color,shape,,salesprice) values (?,?,?,?,?,?,?,?)";     $cordovasqlite.execute(db, query, [purchasetype, stonename, size, weight, pieces, color, shape, salesprice]).then(function (res) {         var alertpopup = $ionicpopup.alert({             title: 'successful!',             template: 'record entered!'         });     }, function (err) {         console.log(err);         window.alert(err);     }); }; });  example.controller("viewitemsctrl", function($scope, $cordovasqlite, $state, $ionicpopup){ // values db..! }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -