保存、检索和上传数据到远程服务器---(AngularJs/Ionic) [英] Save ,retrieve and upload data to a remote server---(AngularJs / Ionic)
问题描述
非常感谢您提供的所有教程,它们在很多方面对我们有很大帮助和帮助.拜托,虽然我是 angular/ionic 的新手,但我手头有问题要解决.
Many thanks for all your tutorials that have greatly helped and helping us in so many ways. Please, i have problem at hands to solve though i'm a newbie in angular/ionic.
1) 我有一个表单,其中包含多个用于收集个人信息(如姓名、性别、出生日期、职业等)的输入.在表单底部,我有图像标签和一个分别用于显示和捕获图像的按钮.我能够捕获并显示捕获的图像.
1) I have a form that contains several inputs to collect personal info like names, gender, DOB, Occupation etc. At the bottom of the form i have image tag and a button to display and capture image respectively. I was able to capture and displayed the captured image.
问题说明:
1) 我想保存所有个人信息,包括捕获的本地存储上的图像.为什么?因为网络不好.
1) I would like to save all the personal info including the captured image on a local storage. Why? because of bad network.
2) 我想检索保存的信息和图像并上传到远程服务器.
2) I would like to retrieve the saved info and image and upload to a remote server.
请,如果您能按照自己的意愿用一个简单而简短的教程来说明这一点,我将不胜感激.再次感谢.
Please, i would be so grateful if you can illustrate this with a simple and short tutorial as you wish. Thanks once again.
推荐答案
您可能需要考虑使用 Cordova sqlite 存储.链接
You may want to consider using Cordova sqlite storage. Link
要做到这一点,
通过以下方式将插件安装到您的 ionic 项目文件夹中:
Install the plugin into your ionic project folder via:
cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin.git
获取 ng-cordova.min.js 并添加到您的 javascript 目录中,将以下代码行添加到您的 index.html 中.
Get ng-cordova.min.js and add into ur javascript directory, add this following line of code into your index.html.
<script src="<your folder>/ng-cordova.min.js"></script>
通过以下方式注入你的 angular 模块(app.js):
Inject into your angular module(app.js) via:
angular.module('starter', ['ionic', 'ngCordova'])
通过以下方式创建数据库:
Create a database via :
.controller('YourController', function(....., $cordovaSQLite){
var db = $cordovaSQLite.openDB("database.db");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS form (id integer primary key, name text, address text, telephone text)");
插入示例:
$scope.insert = function(name, text, telephone) {
var query = "INSERT INTO form (name, text, telephone) VALUES (?,?,?)";
$cordovaSQLite.execute(db, query, [name, text, telephone]).then(function(res) {
console.log("success!");
}, function (err) {
console.error(err);
});
}
然后您的图像文件就可以存储为 blob 并玩得开心!(:
Your image file is then able to store as a blob and have fun ! (:
这篇关于保存、检索和上传数据到远程服务器---(AngularJs/Ionic)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!