That worked like a charm Sander!!

Here's my code now:

    qz.websocket.connect().then(function() {     
          return qz.printers.find();
       }).then(printers => { 
          console.log(printers);
          this.chosePrinter(printers);
          return qz.hid.listDevices(false);
       }).then(devices => {          
          console.log(devices);
          this.choseScale(devices);
       }).then(function() {
          qz.websocket.disconnect();       
       }).catch(function(err) {
         console.error(err);   
       }); 

BTW, could i/should I use a fat arrow on the initial connect statement?

I did read the suggested article you mentioned on promises and it was 
helpful.  I also looked into an alternate approach using await:  But I 
couldn't find a way to  return both the array of HID devices and printers 
without having separate calls (unless I could have two return values).  
Here's how I was able to process the HID devices.

      const getDeviceData = async () => {
          var foo = await qz.websocket.connect();
          var devices = await qz.hid.listDevices(false);
          var bar = await qz.websocket.disconnect();
          return devices;
       }

     getDeviceData().then(result => {
          console.log("len " + result.length);
          let i: number;
          for(i = 0 ; i< result.length; i++) {
             let object = JSON.parse(JSON.stringify(result[i]));
             if (object.product.toLowerCase().indexOf("scale") > 0) 
             {  
                 localStorage.setItem('qzScale', JSON.stringify({ vendorId: 
object.vendorId ,product: object.product , manufacturer: 
object.manufacturer}));           
                 break;
             }
          }
       })

Many thanks for your continued assistance to me and others on this forum!!

Harry



On Wednesday, March 6, 2019 at 4:18:00 AM UTC-8, Sander Elias wrote:
>
> Hi Harry,
>
> I took a closer look to your screenshot. (BTW, pasting snippets as code 
> makes it easier to spot issues and help you)
> It is a 'this' problem indeed.
> In JS, each function had it's own 'this' That means the 'this' in the 
> function, is not your class. Hence the error.
> Replace the function with an arrow function, and your problem will be gone.
>
> .then( devices => this.choseScale(devices))
>
> should do the trick.
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to