我正在使用ionic进行移动应用,我需要在设备旋转时处理视图,因此我使用此代码检测屏幕并更新视图:
$scope.products = [];
$rootScope.dato = [];
ProductsService.getProductsFromCategory($scope.category_id).then(function(data){
$rootScope.dato = data.data.products;
load_data($rootScope.dato);
console.log("############# xxxxdxxxdxxxxdxxxxd ##############" +JSON.stringify($rootScope.dato));
$ionicLoading.hide();
});
$scope.calculateDimensions = function(gesture) {
console.log("############# Calculate produit ##############" +JSON.stringify($rootScope.dato));
$scope.dev_width = $window.innerWidth;
$scope.dev_height = $window.innerHeight;
$scope.devider = parseInt($scope.dev_width / 150);
}
angular.element($window).bind('resize', function(){
$scope.$apply(function() {
console.log("############# test Calculate produit ##############" +JSON.stringify($rootScope.dato));
load_data($rootScope.dato);
})
});
function load_data(products) {
$scope.calculateDimensions();
console.log("############# befir called ##############" +JSON.stringify(products));
$scope.products = [];
while (products.length) {
$scope.products.push(products.splice(0, $scope.devider))
}
console.log("############# after called ##############" +JSON.stringify($scope.products));
console.log("############# befir called ##############" +JSON.stringify($rootScope.dato));
}
我的$ scope.data第一次包含一个json数组但是当我旋转一个设备时,我的$ scope.data显示了一个空数组[]。
感谢。