How to Add an Initial Load in a PullHook Sample

Asked 1 years ago, Updated 1 years ago, 62 views

http://ja.onsen.io/guide/overview.html#UsingPullHook
How can I read the sample in the script without pullhooking it when it is initially displayed?

Thank you for your cooperation.

onsen-ui

2022-09-29 21:33

1 Answers

ons.ready() in the controller invokes the retrieval process.

ons.bootstrap()
    .controller('DemoController', function($scope, $timeout, $http){
        $scope.items=[];
        ons.ready(function(){
            loadJson(function(){});
        });
        $scope.load=function($done){
            loadJson($done);
        };
        $scope.reset=function(){
            $scope.items.length = 0;
        };
        function loadJson($done){
            $timeout(function(){
                $http.jsonp('http://numbersapi.com/random/year?callback=JSON_CALLBACK')
                    .success(function(data){
                        $scope.items.unshift({
                            desc —data,
                            land —Math.random()
                        });
                    })
                    .error(function(){
                        $scope.items.unshift({
                            desc: 'No data',
                            land —Math.random()
                        });
                    })
                    .finally(function(){
                        $done();
                    });
            }, 1000);
        }
    });


2022-09-29 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.