angularjs - How to create promise? -


problem $window.print() called , not when promise success.how can create promise when data populated ? suggestion?

'use strict'; angular.module("printmodule").controller('printcontroller', ['$scope', '$window', '$q', function ($scope, $window, $q) {       $scope.ticketpin = localstorage.getitem("pin");     $scope.payouttime = localstorage.getitem("payouttime");     $scope.payoutamount = localstorage.getitem("payoutamount");      var defer = $q.defer();     defer.resolve($scope.ticketpin);     defer.resolve($scope.payouttime);     defer.resolve($scope.payoutamount);      defer.promise.then(function () {         $window.print();     }) }]); 

function getfromlocalstorage (item, callback)  {     //to prevent errors     if (callback) {         return callback(localstorage.getitem(item)) ;     } }   var callback; callback = function (data) {     //set variable data }   //i make getfromlocalstorage factory myfactory.getfromlocalstorage("itemname", callback); 

caveat, above should able made work have not used localstorage enough know ins, outs, , gotchas, there may need rearrangement of nested return.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -