2

Problem is that print function is called BEFORE angular variables are loaded so in view i get something like this {{ticketPin}} and so on...Any suggestion how can i render angular parameters before print function is called ?

I have accountContentController where i have this :

 $scope.printFunction = function ()
    {
        localStorage.setItem("payoutTime", $scope.testpayoutTime);
        localStorage.setItem("payoutAmount", $scope.testpayoutAmount);
        localStorage.setItem("pin", $scope.testticketPin);
        $window.open("/print");

    }

I have printController where i have this :

$window.print();
Moppo
  • 18,797
  • 5
  • 65
  • 64
uzhas
  • 895
  • 4
  • 13
  • 27
  • possible duplicate of [Prevent double curly brace notation from displaying momentarily before angular.js compiles/interpolates document](http://stackoverflow.com/questions/12866447/prevent-double-curly-brace-notation-from-displaying-momentarily-before-angular-j) – changtung Jul 27 '15 at 11:19

2 Answers2

0

Use ng-cloak or ng-bind to get rid of {{ticketpin}}

<span ng-bind="ticketpin"></span>
Mustafa ASAN
  • 3,747
  • 2
  • 23
  • 34
0

Id depends if you are loading to a scope from promise or other way. But in both cases, it's possible to set watch on these specific parameters. Watch is having arguments of new and old variables and you can check if old value ( suppose null or undefined ) is exchanged by new value ( suppose this value you want to print ). So set watch:

$scope.$watch(function(){ 
    return $scope.testpayoutAmount;
}, function(newVal,oldVal) { 
    if ( newVal != oldVal ) {
        $window.print(); 
    }
});

The problem is, that if you have three variables and you want to know if each is changed. You can set a counter to count to three:

$scope.$watch(function(){ 
    return $scope.testpayoutAmount + $scope.var2 + $scope.var3;
}, function(newVal,oldVal) { 
    if ( newVal != oldVal ) {
        $scope.count++;
    }
    if ( $scope.count == 3 ) 
        $window.print();
});

Here I assume, that one variable my be changed only one time, so from undefined to some value. If there is possible to change it twice or more, then this solution doesn't make sense, because here you must know sum of changes before running app.

changtung
  • 1,614
  • 15
  • 19
  • when i use your first example i dont get print function it just opens me view but it not call print function – uzhas Jul 27 '15 at 10:53
  • do you call $window.print on some action? click etc? In my example, it would be loaded after change of variable, but you can treat ( count == 3 ) as condition for allowing to print. – changtung Jul 27 '15 at 10:57
  • i get always equal old and new value.... what im trying to do is on ng-click to open new window and populate with some data and then call print function ...is it clear to you now? – None Jul 27 '15 at 11:00
  • Why variables aren't loaded ? Is it because of population from promises ? or loading from local Storage? – changtung Jul 27 '15 at 11:05
  • i dont know....i know when i put alert i get values but when it call print function i get {{ticketPin}} and not real value – uzhas Jul 27 '15 at 11:07
  • i think that problem is that angular is loaded before print function thats why i get just {{ticketPin}} – uzhas Jul 27 '15 at 11:09
  • [this](http://stackoverflow.com/questions/14968690/sending-event-when-angular-js-finished-loading) may help. – changtung Jul 27 '15 at 11:14
  • @cyan its not helpful .. i tried directive from that post but i get same results – uzhas Jul 27 '15 at 11:36