Retrieves data for database

Good morning everyone

I’m learning IONIC now and I have a problem. I am using Ionic V1.7.16

I am developing a test application that retrieves data from a local database (as I am using the browser to test, I use the WebSQL, but the application will use SQLite).

The app is very simple.
It creates the database structure and add 1 record.
When the person clicks the Login button, it takes you to another page and displays the page title Login that was automatically added to the database.

The problem is that sometimes shows login times not. (Click the Back button and then the Login again several times).

Looking on the console, every time that Page1 is loaded it prints the login, only on the screen not.

Could anyone help me with this issue?

Below is the code I used:


<!DOCTYPE html>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

        <link rel="manifest" href="manifest.json">
          if ('serviceWorker' in navigator) {
              .then(() => console.log('service worker installed'))
              .catch(err => console.log('Error', err));

        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="cordova.js"></script>
        <script src="js/app.js"></script>
    <body ng-app="starter">
    <ion-nav-bar class="bar-stable bar bar-dark">



       function localSQL(db, sql, dados) { db.transaction( function (tx) {  tx.executeSql(sql, dados); } );  }

angular.module('starter', ['ionic'])
        .run(function ($ionicPlatform, $rootScope) {
            $ionicPlatform.ready(function () {
                if (window.cordova && window.cordova.plugins.Keyboard) {
                if (window.StatusBar) {
                $rootScope.db = null;
                $rootScope.db = window.openDatabase("app_test.db", '1.0', 'app_test', 1024 * 1024 * 100);
                localSQL($rootScope.db, 'DROP TABLE IF EXISTS tb_login', []);
                localSQL($rootScope.db, 'CREATE TABLE IF NOT EXISTS tb_login (id_login INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ds_login NVARCHAR(50) NOT NULL DEFAULT "")', []);
                localSQL($rootScope.db, 'INSERT INTO tb_login (ds_login) VALUES (?);', ['MY LOGIN']);

        .config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

                    .state('page1', {
                        url: "/page1",
                        cache: false,
                        templateUrl: "page1.html",
                        controller: 'Page1Ctrl'

                    .state('login', {
                        url: "/login",
                        cache: false,
                        templateUrl: "login.html",
                        controller: 'LoginCtrl'


        .controller('LoginCtrl', function ($scope, $state) {
            $scope.init = function () {};
            $scope.login = function () {

        .controller('Page1Ctrl', function ($scope, $state, $rootScope) {
            $scope.init = function () {
                db = $rootScope.db;

                        function (tx) {
                            tx.executeSql("SELECT ds_login FROM tb_login", [], function (tx, results) {
                                $scope.title = results.rows.item(0).ds_login;
            $scope.back = function () {


    <ion-view view-title="Login Page" ng-init="init()">
            <button class="button" ng-click="login()">Login</button>


<ion-view view-title={{title}} ng-init="init()">
        Test Page
        <br /><br /><br />
        <button class="button" ng-click="back()">Back</button>

Thank you and sorry for my english

Ronaldo Araujo