app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova', 'ngCookies'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleLightContent();
}
});
})
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('HomePage', {
url: '/HomePage/:id',
templateUrl: 'templates/HomePage.html',
controller: 'HomePageCtrl'
})
.state('login', {
url: '/login',
templateUrl: 'templates/Login.html',
controller: 'LoginCtrl'
});
$urlRouterProvider.otherwise('/login');
});
controllers.js
angular.module('starter.controllers', [])
.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup, $state, $location, $http, $cookieStore) {
$cookieStore.put('mycookie', 'cookie value');
var favoriteCookie = $cookieStore.get('mycookie');
var alertPopup = $ionicPopup.alert({
title: 'favoriteCookie title',
template: favoriteCookie // This does not work on phone.
});})
index.html
<!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">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic/ng-cordova-master/demo/www/lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="lib/ionic/js/cookies.js"></script>
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
</body>
</html>
题:
如果我使用
$cookieStore
,则可以在浏览器上正常使用。但是,当我将项目发布到电话
$cookieStore
时不起作用。我的意思是当我尝试在Android手机中使用$cookieStore
时。$cookieStore
在$ionicPopup.alert
上显示以下错误。undefined
如何通过使用ionic在Android上使用Cookie?
任何帮助将不胜感激。
谢谢。
最佳答案
请投票给这个答案,因为当我发布> _
与其使用似乎在Android上无法正常运行的$ cookieStore,而是将其替换为默认的localStorage。它很好用! :)$cookieStore.set() -> window.localStorage.setItem()$cookieStore.get() -> window.localStorage.getItem()$cookieStore.remove() -> window.localStorage.removeItem()
关于javascript - Ionic Angular JS Cookie不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33172514/