I have an app with a SQLite DB, when I install the app
and I click a link that goes to a search , I can access to
search the SQLite data loaded, everything works well. If
I add a word to the search form and I can see the list off the
that word that I put in the search form field.
But when I close the app and open it back again, and click on the
search link I can´t access neither to the data that
is loaded.
I wonder if the problem is that the second time I open the app
when I click the link to search I can´t find the DB or I need
another code to work along with the link, to find the form an
load the data from the DB ?
I begin loading the data in www/js/app.js to the DB located in
www/contract.db
function bdSQLite() {
window.plugins.sqlDB.copy("contract.db", function() {
db = $cordovaSQLite.openDB("contract.db");
}, function(error) {
console.error("Error al cargar bd " + error);
db = $cordovaSQLite.openDB("contract.db");
});
};
The view is in \www\templates\application-storage\sqLite\html
\contract-list.html
<md-list-item>
<md-input-container md-no-float="" class="md-list-item-full-width">
<input ng-model="filterText" placeholder="Buscar contactos." type="text" autocomplete="off" name="filtername" ng-model-options="{ debounce: 1000 }" >
</md-input-container>
</md-list-item>
<!--Below code it will disable animation to better performance-->
<div ng-if="filterText.length>2" class="row contract-list-item"
ng-repeat="contract in contracts | filter: filterText" >
<div class="col-25 icon-user">
<i class="fa fa-user"></i>
</div>
<div class="col-50">
{{ contract.contacto }} {{ contract.categoria }}
</div>
The controller is in \www\templates\application-storage\sqLite
\js\controller.js also the services in services.js
In the controller.js I make the call to obtein the data
$scope.getContractList();
$scope.getContractList = function () {
$scope.contracts = ContractDB.all();
};//End getContractList.
and access to the services
all: function ()
{
contractList = [];
// Variable for prepare query statement to select all contracts.
var query = "SELECT * FROM contracts";
// Execute query statement from query variable.
$cordovaSQLite.execute(db, query).then(function (res)
{
if (res.rows.length > 0)
{
for (var i = 0; i < res.rows.length; i++)
{
var dataItem = {
id : res.rows.item(i).id ,
contacto : res.rows.item(i).contacto ,
categoria : res.rows.item(i).categoria ,
telephone : res.rows.item(i).telephone ,
email : res.rows.item(i).email
};
contractList.push(dataItem);
}
}
});
return contractList;
},// End select all data.
....
I use Versions
Ionic 1.7.14
Cordova 5.3.3
Node.js 4.4.
and the following plugins
Plugins
“cordovaPlugins”:
“ionic-plugin-keyboard@1.0.8”,
“cordova-plugin-googleplayservices@19.0.3”,
“cordova-plugin-console@1.0.2”,
“cordova-plugin-whitelist@1.2.1”,
“cordova-plugin-transport-security@0.1.1”,
“cordova-plugin-inappbrowser@1.1.1”,
“de.appplant.cordova.plugin.ema…-composer@0.8.2”,
“cordova-sms-plugin@0.1.6”,
“cordova-plugin-splashscreen@3.0.0”,
“cordova-plugin-x-socialsharing@5.0.10”,
“cordova-plugin-contacts@2.0.1”,
“cordova-plugin-inappbrowser@1.3.0”,
“org.apache.cordova.splashscreen@1.0.0”,
“cordova-plugin-dbcopy”,
https://github.com/devgeeks/Ca…,
“id”: “org.devgeeks.Canvas2ImagePlugin”
https://github.com/wymsee/cord…,
“id”: “cordova-plugin-image-picker”
https://github.com/litehelpers…
storage.git#0.7.14”,
“id”: “cordova-sqlite-storage”
Thanks for your support