0

What i am trying to do is to open partial view in new window and call print function, but problem is that partial view is render after print function so i allways get blank page. I tried with $timeout function but i get same result. Is it possible to do this somehow without using something like this:

  $scope.print = function () {


        setTimeout(function () { print()}, 1000);
    }

I want to avoid delay in this way

EDIT: this is how i use now but i dont like it :

   $scope.ConfirmTicketPayOut = function (ticketPin, username) {
        $scope.ticketPin = ticketPin;
        localStorage.setItem("pin", ticketPin);
        accountDataProviderService.confirmTicketPayOut(ticketPin, username)
        .then(function (response) {

            $scope.confirmTicketPayOut = response;
            if ($scope.confirmTicketPayOut.Result == true) {

                $window.open('/print');

            }
        });
        localStorage.clear();
    }
   $scope.print = function () {


        setTimeout(function () { print()}, 1000);
    }
uzhas
  • 895
  • 4
  • 13
  • 27
  • can you post the code? – EsseTi Jul 24 '15 at 11:59
  • @EsseTi there is my code where i "try" to do print – uzhas Jul 24 '15 at 12:04
  • @EsseTi is there anything clear to you? :) – uzhas Jul 24 '15 at 12:09
  • what are you expecting to happen with the second window? You are calling print in the main window using no reference to the new window – charlietfl Jul 24 '15 at 12:59
  • If you return a promise with your print function your problem will be solved. Also if you do not return a promise your UI will freeze even if you call the print() function after the UI is loaded. Look into the Q module for promises. It should be a very easy implementation. Here is a thread with the same question http://stackoverflow.com/questions/31610764/print-function-is-calling-before-partial-view – Ivan Stoyanov Jul 24 '15 at 13:00
  • @charlietfl is it possible to reference to new window from main window? – uzhas Jul 24 '15 at 13:03
  • of course it is.... read docs for `window.open` ..it returns window instance. Should use `onload` handler also – charlietfl Jul 24 '15 at 13:04
  • @charlietfl can u help me a littlebit? :D – uzhas Jul 24 '15 at 13:07
  • bind a load handler to the new window and run your print code there – charlietfl Jul 24 '15 at 13:08
  • @charlietfl do u understand what im trying to do here? :) – uzhas Jul 24 '15 at 13:09
  • you want the contents of the new window to print ...correct? – charlietfl Jul 24 '15 at 13:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84183/discussion-between-uzhas-and-charlietfl). – uzhas Jul 24 '15 at 13:11
  • look at this post: [link](http://stackoverflow.com/questions/19637312/is-there-an-angular-way-of-printing-a-div-from-a-html-page/23894124#23894124) – changtung Jul 24 '15 at 13:30

0 Answers0