简体   繁体   English

我如何在内存数据库中使用离子应用程序

[英]How can i use in memory database to my Ionic app

I am new to ionic app development and also In Memory database, how can i use in memory database to my ionic app. 我是离子应用程序开发的新手,也是内存数据库中的新手,如何在离子数据库应用程序的内存数据库中使用。 For My Ionic app am using AngularJS, HTML5 and CSS. 对于My Ionic应用程序,我正在使用AngularJS,HTML5和CSS。 I need Data transaction from My Ionic app to Inn memory Database. 我需要将数据从My Ionic应用程序传输到Inn内存数据库。 Please give me some useful links. 请给我一些有用的链接。 Thanks In advance. 提前致谢。

try this way..! 尝试这种方式..!

command to install local storage 命令安装本地存储

bower install a0-angular-storage

in index.html 在index.html中

<script src="lib/angular-storage.min.js"></script>

make service : 提供服务:

angular.module('app', ['angular-storage'])
.factory('UserDetailsService', function ( store ,$rootScope) {
    var self = {};
    self.getUsers = function () {
        var users = store.get('_userList');
        if (users){
            return users;
        }else{
            return null;
        }
    };
    self.setUsers = function(UserList) {
        $rootScope.users = UserList;
        store.set('_userList', UserList);
    };
    return self;
});

in controller: 在控制器中:

.controller('UserCtrl', function ($scope,  UserDetailsService,store) {
    //to store data..!
    $scope.doLogin = function () {
        $http.post('**** URL *****', $scope.loginData).
            success(function (response) {
                $scope.users = response.result;
                UserDetailsService.setUsers($scope.users);// call to service..!
            }).error(function (response) {
            });
    };
    //to get local store list
    $scope.users = UserDetailsService.getUser();
    //to remove local store data
    $scope.toRemoveLocalData = function () {
        store.remove('_userList');
    };
})

one more simple way .. 一种更简单的方法 ..

you can use local storage , First make a angular factory , then use this angular factory in your ionic app controller , sample code is given below: 您可以使用本地存储 ,首先创建一个角度工厂 ,然后在您的ionic app控制器中使用该角度工厂 ,示例代码如下:

Angular Factory :: 角工厂 ::

 .factory('$localstorage', ['$window', function($window) {
     return {
        set: function(key, value) {
            $window.localStorage[key] = value;
        },
        get: function(key, defaultValue) {
            return $window.localStorage[key] || defaultValue;
        },
        setObject: function(key, value) {
            $window.localStorage[key] = JSON.stringify(value);
        },
        getObject: function(key) {
            return JSON.parse($window.localStorage[key] || '{}');
       }
   }
}]);

Angular Controller : 角度控制器

 .controller('mainCtrl', function($scope, $localstorage) {
       // set data to $localstorage
       // you can use this json data anywhere in your app
       $localstorage.setObject('object_name', json_data);



      // get $localstorage data
      var json_data = $localstorage.getObject('object_name'); 
 });

NB:: localstorage is only for limited data. 注意:本地存储仅用于有限的数据。 For large number of data, you better sqlite 对于大量数据,您最好使用sqlite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ionic 3 angular应用程序中使用单选按钮选择性别? - How can I use radio button for choosing gender in my ionic 3 angular app? 如何在我的应用程序中使用数据库 sqlite? - How can i use the database sqlite in my application? 我如何将数据从我的数据库或网站放到我的移动应用程序中(我使用 HTML5 和 ionic)? - how can i put data from my database or website to my mobile application (im working with HTML5 and ionic)? 我可以在JavaScript中使用多少内存? - How much memory can I use in javascript? 如何在离子应用程序中修改下载的HTML? - How can i modify downloaded html in an ionic app? 如何使用json的ionic 2在HTML中显示此数据? - How can i show this data in my html with ionic 2 from a json? 我如何在离子应用程序中添加或使用Google Map - How i can add or use google-map in ionic application 如何从数据库中获取值,并在输入字段中使用和显示它? - How can I get a Value from my Database and use and show it inside an Input Field? 如何使用HTML和CSS为Java应用程序创建用户界面? - How can I use HTML & CSS to create the user interface for my java app? 如何使用以下HTML为我的android应用动态创建wordclouds? - How can I use the following html to dynamically create wordclouds for my android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM