javascript - Print function is rendered before angular loads values? -
i need values on first 1 image when call print function on second pictures.i tried
angular.element(document).ready(function(){ $window.print });
and tried use ng-binding
, ng-cloak
results on second image
i have page have button:
i have controller have:
$scope.printfunction = function () { localstorage.setitem("payouttime", $scope.testpayouttime); localstorage.setitem("payoutamount", $scope.testpayoutamount); localstorage.setitem("pin", $scope.testticketpin); $window.open("/print"); }
and when view open have controller on view:
$scope.ticketpin = localstorage.getitem("pin"); $scope.payouttime = localstorage.getitem("payouttime"); localstorage.payoutamount = localstorage.getitem("payoutamount"); $window.print();
how can render variables before print function?
there in lies problem. it’s rat race: whatever happens there first wins. it’s render, sometimes
we can use slight hack settimeout().
$scope.printfunction = { afterrender: function () { localstorage.setitem("payouttime", $scope.testpayouttime); localstorage.setitem("payoutamount", $scope.testpayoutamount); localstorage.setitem("pin", $scope.testticketpin); $window.open("/print"); }, render: function () { //render template settimeout(this.afterrender.bind(this), 0); } }
updated:
there few solutions. code needs know when value has changed.
right there no way our code directly notified of changes on object.
instead there 2 main strategies.
- one strategy use special objects, data set via methods, not property assignments. changes can noted, , page can updated. has downside in must extend special object. also, assigning, must use more verbose form obj.set('key', 'value') instead of obj.key = 'value'.
- angularjs takes different approach: allow value used binding target. @ end of javascript code turn, check see if value has changed. may seem inneficient @ first, there clever strategies reduce performance hit. big benefit can use normal objects , update our data want, , changes noticed , reflected in our bindings.
for strategy work, need know when data has possibly changed, , $scope.$apply comes play.
i hope help
Comments
Post a Comment