我是Cordova + Ionic的新手,并试图通过ngcordova偏好方法访问我的Android设备中的共享首选项,但我在cordova 6.00中遇到此错误。离子1.7.14甚至所有必需的配置都已完成。 (根据我的知识,如果我不正确,请纠正我)。已附上app.js和Index.html的源代码。请帮忙。
angular.module('starter', ['ionic','ngCordova'])
.controller('MyCtrl', function($scope, $cordovaPreferences) {
$scope.storedata = function() {
$cordovaPreferences.store('key', 'myMagicValue')
.success(function(value) {
alert("Success: " + value);
})
.error(function(error) {
alert("Error: " + error);
}
)
};
$scope.fetch = function() {
$cordovaPreferences.fetch('key')
.success(function(value) {
alert("Success: " + value);
})
.error(function(error) {
alert("Error: " + error);
})
};
})
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter" ng-controller="MyCtrl">
<input type="button" value="ClikMe" ng-click="storedata()" ></input>
</body>
</html>
&#13;
这是错误日志。
TypeError: $cordovaPreferences.store is not a function
at Scope.$scope.storedata (app.js:32)
at fn (eval at <anonymous> (ionic.bundle.js:26457), <anonymous>:4:218)
at ionic.bundle.js:62386
at Scope.$eval (ionic.bundle.js:29158)
at Scope.$apply (ionic.bundle.js:29257)
at HTMLInputElement.<anonymous> (ionic.bundle.js:62385)
at HTMLInputElement.eventHandler (ionic.bundle.js:16583)
at triggerMouseEvent (ionic.bundle.js:2948)
at tapClick (ionic.bundle.js:2937)
at HTMLDocument.tapMouseUp (ionic.bundle.js:3013)(anonymous function) @ ionic.bundle.js:25642(anonymous function) @ ionic.bundle.js:22421Scope.$apply @ ionic.bundle.js:29259(anonymous function) @ ionic.bundle.js:62385eventHandler @ ionic.bundle.js:16583triggerMouseEvent @ ionic.bundle.js:2948tapClick @ ionic.bundle.js:2937tapMouseUp @ ionic.bundle.js:3013