nativescript-sqlite和angular2模块未找到异常

Chr*_*ian 5 sqlite android angularjs nativescript angular

我有一个带有angular2应用程序的nativescript for android,我想利用nativescript-sqlite的离线存储功能.问题是我得到以下异常:

Failed to find module: "nativescript-sqlite", relative to: /app/tns_modules/
Run Code Online (Sandbox Code Playgroud)

在下面的行:

var Sqlite = require("nativescript-sqlite");
Run Code Online (Sandbox Code Playgroud)

我使用以下命令安装插件

tns插件添加nativescript-sqlite

我创建了一个带有角度服务的db.service.ts文件,其内容如下:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

对你的帮助表示感谢.

Tim*_*ton 1

大多数模块错误可以通过删除平台然后再次添加来解决。

对于 Android 来说,这将是:

tns platform remove android
tns platform add android
Run Code Online (Sandbox Code Playgroud)

对于 iOS:

tns platform remove ios
tns platform add ios
Run Code Online (Sandbox Code Playgroud)

正如您在评论中看到的那样,该问题已得到解决。简单回答一下,让大家都能看到