Angular2:问题条形码函数未定义



我在Angular 2中更新鲜,我正在开发一个离子2应用程序,因为我正在使用条形码扫描仪插件,问题是我正在根据数字扫描条形码订单,但不幸的是,我会遇到一个错误,以下显示

error.log

**EXCEPTION: Error in ./AcceptOrdersFromVanPage class AcceptOrdersFromVanPage - inline template:64:8 caused by: this.barcode(...) is undefined  main.js:64726:9
ORIGINAL EXCEPTION: this.barcode(...) is undefined  main.js:64728:13
ORIGINAL STACKTRACE:  main.js:64731:13
AcceptOrdersFromVanPage/this.vendorbarcode@http://localhost:8100/build/main.js:26913:17
AcceptOrdersFromVanPage</AcceptOrdersFromVanPage.prototype.AcceptOrderfromVendor@http://localhost:8100/build/main.js:27016:9
anonymous/View_AcceptOrdersFromVanPage2.prototype.handleEvent_14@/AppModule/AcceptOrdersFromVanPage/component.ngfactory.js:428:21
DebugAppView</DebugAppView.prototype.eventHandler/<@http://localhost:8100/build/main.js:127682:24
decoratePreventDefault/<@http://localhost:8100/build/main.js:46755:36
O</d</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9712
onInvokeTask@http://localhost:8100/build/main.js:44826:28
O</d</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9640
O</v</e.prototype.runTask@http://localhost:8100/build/polyfills.js:3:7064
t/this.invoke@http://localhost:8100/build/polyfills.js:3:10834
EventListener.handleEvent*u@http://localhost:8100/build/polyfills.js:2:27976
O</d</t.prototype.scheduleTask@http://localhost:8100/build/poly[…]  main.js:64732:13
ERROR CONTEXT:  main.js:64735:13
Object { _view: Object, _nodeIndex: 14, _tplRow: 64, _tplCol: 8 }  main.js:647**

这是我的模板.html

<ion-content>
  <div *ngIf="torders">
  <ion-card *ngFor='let d of torders; let i = index;'>
    <ion-card-header>
      <p><strong>Total Order(s) : </strong>{{d.Total_Orders}}</p>
    </ion-card-header>
    <ion-row>
      <ion-col>
        <button ion-button icon-left clear small (click)="Accept(i, torders)">
          Accept
        </button>
      </ion-col>
    </ion-row>
  </ion-card>
  </div>
</ion-content>

这是我的.ts文件

export class AcceptPage implements OnInit {
 bartxt: any;
  orderids: any;
  orderarray: any;
  orderstring: any;
  totalorders: any;
  _i: number = 0;
barcode(index, torders) {
    BarcodeScanner.scan().then((barcodeData) => {
      if (barcodeData.cancelled) {
        alert("User cancelled the action!");
        return false;
      }
      this.bartxt = barcodeData.text;
      if (this.bartxt != '') {
        this.authservice.validate(this.bartxt, this.orderids)
          .subscribe(data => {
            if (data == "BARCODE_FOUND") {
               alert("scanned successfully");
                if (this._i == (this.totalorders - 1)) {
                  this._i = 0;
                  this.finalacceptvendor(index, torders);
                } else {
                  this._i++;
                  this.vendorbarcode(index, torders);
                }
            } else {
              alert("wrong qr code")
              this.vendorbarcode(index, torders);
            }
          });
      }
    });
  }
public vendorbarcode = function (index, torders) {
    this.totalorders = this.torders[index].Total_Orders;
    this.orderarray = this.orderstring.split(',');
    this.orderids = this.orderarray[this._i];
    while (this._i < this.totalorders) {
      this.barcode(index, torders)
        .then(function (response) {
        });
    }
  }
Accept(index, torders) {
    this.vendorbarcode(index, torders);
  }
finalacceptvendor(index, torders) {
    this.authservice.finalFunction(this.torders[index].OrderId)
      .subscribe(data => {
        if (data == 'UPDATE_SUCCESS') {
          alert("success");
        } else {
          alert("fail");
        }
      },
      err => {
        console.log('err');
      });
  }
}

我已经介绍了一些与我的问题有关的帖子,但无法对问题进行整理。请帮助我对此问题进行排序...

您没有从barcode()方法返回,因此您应该使用为

barcode(index, torders) : Promise<any> { ///////////////
   return BarcodeScanner.scan().then((barcodeData) => {
      if (barcodeData.cancelled) {
        alert("User cancelled the action!");
        //return false;//////////remove this line
      }
      this.bartxt = barcodeData.text;
      if (this.bartxt != '') {
        this.authservice.validate(this.bartxt, this.orderids)
          .subscribe(data => {
            if (data == "BARCODE_FOUND") {
               alert("scanned successfully");
                if (this._i == (this.totalorders - 1)) {
                  this._i = 0;
                  this.finalacceptvendor(index, torders); 
                } else {
                  this._i++;
                  this.vendorbarcode(index, torders);    
                }
            } else {
              alert("wrong qr code")
              this.vendorbarcode(index, torders); 
            }
          });
      }
    });
  }

barcode方法应返回承诺,如果vendorbarcode方法正在尝试进行this.barcode(index, torders).then(...)

相关内容

  • 没有找到相关文章

最新更新