I have made a simple app using Ionic and AngularJS which takes values from one view, stores data into SQLite database and then displays the added values in another view. I have made use of ion-tabs for displaying the views. But when I switch into another view after adding the items, I am unable to see the added value. I need to close the app and launch it again to see the updated list.
Is there any way that I can reload the view when I switch into 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 even added 'reload:true' inside its state but it still doesn't work. :( Please help. Thanks 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 INTO 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);
});
};