加载页面时如何刷新离子控制器

时间:2018-07-03 12:08:47

标签: android html css angularjs ionic-v1

这是控制器-它的a标签移动页面数据本身是第一次加载的。但仅在重新加载时显示?

.controller('TestCntrl', function($scope, $state, $route, $window, Chats, $rootScope, $cordovaToast, $location, $ionicSlideBoxDelegate, $window, $ionicGesture, WebService, $localStorage) {
    // With the new view caching in Ionic, Controllers are only called
    // when they are recreated or on app start, instead of every page change.
    // To listen for when this page is active (for example, to refresh data),
    // listen for the $ionicView.enter event:
    //
    //$scope.$on('$ionicView.enter', function(e) {
    //});
    $scope.Height = $window.innerHeight - 30;
    $scope.chats = Chats.all();
    $scope.remove = function(chat) {
        Chats.remove(chat);
    };
    $scope.nextSlide = function() {
        $ionicSlideBoxDelegate.next();
    };

    //controller for category types for products.
    $route.reload();
    WebService.invokeService('home', 'POST', 'http://' + $rootScope.ip + 'php/products_category.php')
        .success(function(data) {
            $route.reload();
            $scope.productCategories = data.productCategories;
            console.log("PRODUCT CATEGORIES ", $scope.productCategories);


            var data = {
                category_id: $localStorage.category.c_id,
                product_category: $scope.productCategories[0].product_category
            }
            var jsonStr = angular.toJson(data);
            WebService.invokeService('home', 'POST', 'http://' + $rootScope.ip + 'php/productsList.php', jsonStr)
                .success(function(data) {
                    //  $scope.productsList = data.productsList;
                    $scope.productsListd = data.productsList;

                    console.log($scope.productsListd);



                    // $window.location.reload();
                    // location.reload(true);



                    $route.reload();
                })
                .error(function(data) {
                    $cordovaToast.showLongCenter('Please Check Your Data Connection!');
                });

        })
        .error(function(data) {
            $cordovaToast.showLongCenter('Please Check Your Data Connection!');
        });


    $scope.myActiveSlide = 0;
    $scope.reportSlideChanged = function(slideNum) {
        console.log('SlideNum = ' + slideNum);

        // switch(slideNum) {
        // case 0:
        var data = {
            category_id: $localStorage.category.c_id,
            product_category: $scope.productCategories[slideNum].product_category
        }
        var jsonStr = angular.toJson(data);
        WebService.invokeService('home', 'POST', 'http://' + $rootScope.ip + 'php/productsList.php', jsonStr)
            .success(function(data) {
                $scope.productsList = data.productsList;

                console.log($scope.productsList);


                //  $window.location.reload();
                //  window.location.reload(true);

                $route.reload();


            })
            .error(function(data) {
                $cordovaToast.showLongCenter('Please Check Your Data Connection!');
            });
    }




    $scope.productDetailsPage = function(product) {
        $localStorage.product_Details = product;
        $state.go('productDesc');
    }
})

0 个答案:

没有答案