Ho un nativescript con l'applicazione angular2 per Android dove voglio sfruttare il nativescript-sqlite delle capacità di archiviazione offline. Il problema è che sto ottenendo la seguente eccezione:nativescript-sqlite e angular2 modulo non trovato eccezione
Failed to find module: "nativescript-sqlite", relative to: /app/tns_modules/
sulla linea di seguito:
var Sqlite = require("nativescript-sqlite");
installo il plugin utilizzando il seguente comando
TNS plugin di aggiungere nativescript-sqlite
Ho creato un file db.service.ts con e un servizio angolare, il contenuto di seguito:
import {Injectable} from "@angular/core";
import {Config} from "../config";
import {Observable} from "rxjs/Rx";
import "rxjs/add/operator/do";
import "rxjs/add/operator/map";
import {Profile} from "../profile/profile";
var Sqlite = require("nativescript-sqlite");
@Injectable()
export class DbService {
database: any;
constructor() {
(new Sqlite("gtel.db")).then(db => {
this.database = db;
db.resultType(Sqlite.RESULTSASOBJECT);
this.database.execSQL("CREATE TABLE IF NOT EXISTS profile (id INTEGER PRIMARY KEY AUTOINCREMENT," +
" username TEXT, idnumber TEXT, firstname TEXT, lastname TEXT, mobilenumber TEXT, emailaddress TEXT)").then(id => {
console.log("created table profile")
}, error => {
console.log("created table profile error", error);
});
}, error => {
console.log("OPEN DB ERROR", error);
});
}
createProfile(profile: Profile){
return this.database.execSQL("INSERT INTO profile(username, idnumber, firstname, lastname, mobilenumber, emailaddress) VALUES (?, ?, ?, ?, ?, ?)",
[profile.username, profile.idNumber, profile.firstName, profile.lastName, profile.mobileNumber, profile.emailAddress]);
}
getProfile(id: number){
return this.database.get('select * from Hello where id=?', [id])
}
handleErrors(error: Response) {
console.log(JSON.stringify(error.json()));
return Observable.throw(error);
}
}
Il vostro aiuto sarà molto apprezzato.
RISOLTO: Ho ricevuto aiuto dall'autore del plugin nativescript, quello che dovevo fare era rimuovere e quindi aggiungere la piattaforma Android. –
@ Majuta Puoi aggiungere la tua risposta che sarà più utile per gli altri come me. Grazie. –