The truth is not that I’m doing wrong, but always get the same error
Error: [$injector:unpr] Unknown provider: $$cookieReaderProvider <- $$cookieReader <- $cookies <- auth <- $cookies
I am using this way all:
<script src="js/angular-cookies.js"></script>
App js :
angular.module('SharedServices', ['ionic','ngCordova','ngMap','ngCookies'])
.run(function($ionicPlatform,$ionicSideMenuDelegate,$rootScope) {
$ionicPlatform.ready(function() {
$rootScope.login = true;
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
document.addEventListener('touchstart', function (event) {
// workaround for Android
if ($ionicSideMenuDelegate.isOpenLeft()) {
event.preventDefault();
}
});
});
});
angular.module('ionicApp', ['ionic','SharedServices','ionicLazyLoad','ngCordova','ionic.contrib.frostedGlass','ngMap','ngCookies'])
.factory("auth", function($cookies,$cookieStore,$location){
return{
login : function(username, password)
{
//creamos la cookie con el nombre que nos han pasado
$cookies.username = username,
$cookies.password = password;
//mandamos a la home
$location.path("/home");
},
logout : function()
{
//al hacer logout eliminamos la cookie con $cookieStore.remove
$cookieStore.remove("username"),
$cookieStore.remove("password");
//mandamos al login
$location.path("/login");
},
checkStatus : function()
{
//creamos un array con las rutas que queremos controlar
var rutasPrivadas = ["/home","/dashboard","/login"];
if(this.in_array($location.path(),rutasPrivadas) && typeof($cookies.username) == "undefined")
{
$location.path("/login");
}
//en el caso de que intente acceder al login y ya haya iniciado sesión lo mandamos a la home
if(this.in_array("/login",rutasPrivadas) && typeof($cookies.username) != "undefined")
{
$location.path("/home");
}
},
in_array : function(needle, haystack)
{
var key = '';
for(key in haystack)
{
if(haystack[key] == needle)
{
return true;
}
}
return false;
}
}
})
Which is not bad for all this, though I still examples is always the same error.