ReferenceError:isUndefined未在angular-local-storage中定义

时间:2015-05-21 18:37:38

标签: angularjs cordova local-storage

我正在使用visual studio cordova,angular js和离子框架开发html 5移动应用程序。在那,我需要将一些值保存到localStorage。我关注了一些文章,但在将值保存到本地存储时会出现错误。

<!doctype html>
<html ng-app="myApp">
 <head>    <title>Test app</title></head>
<body ng-app="myApp" ng-controller="MainCtrl">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="angular-local-storage.js"></script>
    <script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>

    <script>
        var myApp = angular.module('myApp', ['ionic', 'LocalStorageModule']);

        myApp.controller('MainCtrl', ['$scope', 'localStorageService', function ($scope, localStorageService) {

            $scope.test = function () {
                var storageType = localStorageService.getStorageType();
                console.log(storageType);
                localStorageService.set('test', 'val');
            }
        }]);
    </script>
    <div>
        <input type="button" ng-click="test()" value="add new">
    </div>
</body>
</html>

抛出ReferenceError: isUndefined is not defined at Object.addToLocalStorage

任何想法??

1 个答案:

答案 0 :(得分:0)

这是一个使用您的应用程序plnkr

的plunker
var myApp = angular.module('myApp', ['ionic' ,'LocalStorageModule']).config(function(localStorageServiceProvider) {
localStorageServiceProvider
  .setPrefix('cars')
  .setStorageType('localStorage')
  .setNotify(false, false);
  }).controller('MainCtrl', ['$scope', 'localStorageService', function ($scope, localStorageService) {

        $scope.test = function () {
            var storageType = localStorageService.getStorageType();
            console.log(storageType);
            localStorageService.set('test', 'val');
        }
    }]);