mercredi 27 avril 2016

my first cordova with ionic framework app, i use sqlite database, my crud operations didnt work

this is my first app on cordova with ionic framework, i use sqlite for database but my crud operation didn't work

no alert anything from js

thanks before..

var db = null;


var starter = angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform, $cordovaSQLite) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
        db = $cordovaSQLite.openDB({name: "pre.db"});
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS Ident (Id INTEGER PRIMARY KEY, FirstName text, LastName text)");
    });
})
//this for insert js, 

starter.controller('DBController', function($scope, $cordovaSQLite) {
    $scope.resultData = "";
    $scope.peopleList = [];
    
    $scope.insert = function(FirstName, LastName) {
        $scope.peopleList = [];
        var query = "insert into Ident (FirstName, LastName) values (?,?)";
        $cordovaSQLite.execute(db,query,[FirstName,LastName]).then(function(result) {
            $scope.resultData = "Insert OK.";
        }, function(error){
            $scope.resultData = "Insert FAIL!";
        });
    }

Aucun commentaire:

Enregistrer un commentaire