离子localStorage选择

时间:2017-06-18 01:21:13

标签: ionic-framework local-storage

我想在我的离子应用中创建设置页面

HTML:

<select class="selectCountry">
    <option value="fr">France</option>
    <option value="usa">USA</option>
</select>

Controler.js

angular.module('starter.controllers', ['ionic', 'ngStorage'])

.controller('SettingsCtrl',function($scope, $localStorage){
// what to do to save and data from <select> & use if condition 
});

2 个答案:

答案 0 :(得分:0)

您可以将ng-model放在select上并触发onchange功能

<select class="selectCountry" ng-model="selectCountry" ng-change="save()">
        <option value="fr">France</option>
        <option value="usa">USA</option>
    </select>

并在控制器中

     angular.module('starter.controllers', ['ionic', 'ngStorage'])

            .controller('SettingsCtrl',function($scope, $localStorage){
            // what to do to save and data from <select> & use if condition 
    $scope.save = function(){
    $localStorage.selectCountry= $scope.selectCountry; // set
alert($localStorage.selectCountry); // get
    }

        $localStorage.selectCountry = $localStorage.selectCountry; // get
            });

检查文档NgStorage

我创建了这支笔Here

答案 1 :(得分:0)

.service('storage', function() {
      var myjsonObj = "nothing";//the object to hold our data
     return {
     setJson:function(name, item){
            window.localStorage.setItem( name, item );


     },
     getJson:function(name){
      return window.localStorage.getItem( name );
     }
     }
    })

如果你想存储和检索变量。

storage.setJson("nameOfSetting", "theVariableYouWannaStore");
var theVariableYouStored = storage.getJson("nameOfSetting");