ionic 监听路由事件变化

(function(){
angular.module("cakeStore", ["ngRoute", "ionic","cookieServiceModule","localStorageServiceModule","configModule", "getcakeDataModule","cakeListCtrlModule","cakecarModule", "cakeDetailCtrlModule","userModelModule","userModule","orderModule","reloModule","orderModule","submitdanModule","myModule"])
.service("shopcarData", ["localStorageService", function(localStorageService){
var data = localStorageService.getData("shopcar");
if (data) {
this.data = data;
} else {
this.data = {};
}
}])
.controller("cakeCtrl",["$rootScope","$scope","$location","shopcarData","localStorageService","$ionicSideMenuDelegate","$ionicPopup","cookieService","getcakeData","$routeParams",function($rootScope,$scope,$location,shopcarData,localStorageService,$ionicSideMenuDelegate,$ionicPopup,cookieService,getcakeData,$routeParams){

/**/
$rootScope.$on('$routeChangeSuccess',
function() {
var route = window.location.href;
if(route.indexOf('/cakeDetail/') != -1){
$scope.det = true;
}else{
$scope.det = false;
}
}
);
/**/
$scope.countShopcar = 0;
//监听购物车信息变化
$scope.$watch(function(){
return shopcarData.data;
}, function(){
var num = 0;
var total = 0;
for (var i in shopcarData.data) {
num ++;
total += shopcarData.data[i].cake_price * shopcarData.data[i].shopcar_num;
}
$scope.countShopcar = num; //改变购物车数量
$scope.total = total; //改变总价

//把购物车信息填入缓存
localStorageService.setData('shopcar', shopcarData.data);

}, true);

getcakeData.requestData("cate.php",{},function(data){
$scope.cates = data;
console.log($scope.cates);
},function(error){
console.log(error);
})

$scope.gotoShopcar = function(){
if(cookieService.getCookie("user")==undefined){
var alertPopup = $ionicPopup.alert({
template:'请用户登录账号'
});

$location.path("relo");

}else{
$location.path("shopcar");
}

}
$scope.toggleLeft = function() {
$ionicSideMenuDelegate.toggleLeft();
};
//退出登录
$scope.logout = function(){
var user = {};

user.username = cookieService.getCookie('user');

$scope.user = user;

//删除cookie
cookieService.deleteCookie("user");
shopcarData.data={ };
//删除数据
$scope.user.username = false;
}

}])
.controller("mainCtrl",["$scope","cookieService","shopcarData",function($scope,cookieService,$ionicSideMenuDelegate,shopcarData){
var user = {};

user.username = cookieService.getCookie('user');

$scope.user = user;

// console.log($scope.user.username);

}])

})()

上一篇:node中的favicon.icon请求


下一篇:poj 3264 RMQ