How to determine when content is uploaded?

I am creating a print page for my site: http://vivule.ee/0/print

I want to initiate window.print()when the page has loaded. I tried different approaches, but to no avail. I know this is possible because I can listen to finished Ajax calls, but how to do it in Angular?

My info path: HTML → angular → php-> mysql table-> php-> json → angular → HTML

+4
source share
3 answers

OK, this works using promises, $ watch, $ timeout and setTimeout

About promises: http://andyshora.com/promises-angularjs-explained-as-cartoon.html

angular $watch: $scope. $watch $scope. $ AngularJS?

, : http://vivule.ee/0/print

, ( ):

if($routeParams.print){

    //Set variable for $watch to listen
    $scope.game = null;

    //Start script only after angular has changed content in ng-view
    $scope.$on('$viewContentLoaded', function(){

        //Listen to $scope.game variable change
        $scope.$watch('game', function(newVal, oldVal){

            //Force angular not to fire script on load
            if(newVal != oldVal) {

                //Force script to run AFTER ng-repeat has rendered its things to the DOM
                $timeout(function(){

                    //And finally setTimout to wait for browser to render the custom fonts for print preview
                    setTimeout(function(){

                        //Print document
                        window.print();
                        //window.close();
                    }, 100);
                }, 0);
            }
        }, true);
    });
}
+2

$viewContentLoaded , ngView . [link]: https://docs.angularjs.org/api/ngRoute/directive/ngView ngView, , , .

 $scope.$on('$viewContentLoaded', function(){
    $window.print();
  });
+3

(Ajax) ,

  getApplication.then( () {// $ scope.isApplicaionLoaded = true; });

- = "isApplicaionLoaded"

0
source

All Articles