Database TypeError: Cannot read property 'executeSql' of undefined


#1

My code

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
 import 'rxjs/add/operator/map';

/*
  Generated class for the DatabaseProvider provider.
  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class DatabaseProvider {
	//public sql:string;
		public db:SQLiteObject;
		private isOpen:boolean;
  constructor(public http: HttpClient, private sqlite: SQLite) {
	 
	  if(!this.isOpen)
	  { 
		

		  this.sqlite= new SQLite();
		   this.sqlite.create({name: "data.db", location: "default"}).then((db : SQLiteObject) => {
                    this.database = db;
                }, (error) => {
                    console.log("ERROR: ", error);
            }); 
		  
		  
		  
		  this.sqlite.create({name: "data.db", location: "default"}).then((result) => 
		  {
			  
			  this.db.executeSql("CREATE TABLE if not exists `save` (  `id` int(11) PRIMARY KEY AUTOINCREMENT,  `temple` longtext NOT NULL,  `active` int(1) NOT NULL DEFAULT '1')",[]); 
			  this.isOpen = trure;
			
		  })
		  .catch((error: any) => 
		  {
			 console.log(error);
		 });
		  
	  }
	  }
    
  adddatabase(data:string)
  {
		
		 let sql = "insert into `save` (`temple`) values("+data+")";
			//this.db.executeSql(
			this.db.executeSql(sql,[]).then(() => {
        console.log(result);
      })
      .catch((error: any) => {
         console.log(e);
          });
    }
     
	
	

	
	  
	  
  }