如何修复可观察的订阅正在打印任何数据

时间:2019-05-11 06:58:15

标签: javascript angular rxjs observable

我的错误是,当我到达this.autoPrinter();时,他们应该打印出可以正常工作的文本,我认为问题在可观察的范围内,但我坚持认为,我不知道我是否真的需要其他帮助!!!

我尝试将方法autoprinter置于订阅之外,内部以及之前,但是仍然没有任何内容可以打印为空白,但是该打印机方法在其他组件上是可以正常工作的

private CTomatic(orders: Array<Order>): void {
  const Ct = Number(window.localStorage.getItem('defaultCookingTime'));
  if (orders.length > 0) {
    orders.forEach(order => {
      if (
        order.partner_order_state === ORDER_STATE.NEWORDER &&
        (window.localStorage.getItem('cookingTime') === 'true' ? true : false)
      ) {
        this.ordersService
          .takeOrder(order.id, this.cookingTime(order, Ct))
          .retry(5)
          .subscribe(
            result => {
              this.autoPrinter();
              this.autoupdatethatshit();
            },
            (err: HttpErrorResponse) => {
              const error = err.error ? err.error.error.message : err.statusText;
              this.snackbarService.showMessageSnackbar(error);
              this.autoupdatethatshit();
            }
          );
      }
    });
  }
}

public autoPrinter(): void {
  if (this.notificationPrintIsEnable === true) {
    window.setTimeout(() => this.printerService.print(), 2000);
  }
}

public autoupdatethatshit(): void {
  setTimeout(() => {
    this.ordersService.getOrders();
  }, 5000);
}


--------------in this method the print method works fine-------------

public takingOrder() {
  if (!this.disabled) {
    this.disabled = true;
    this.showLoading.emit(true);
    this.ordersService
      .takeOrder(this.orderDetail.id, this.cookingTime)
      .subscribe(
        result => {
          this.takeOrderEvent.emit({
            id: this.orderDetail.id,
            cooking_time: this.cookingTime
          });
          this.disabled = false;
          this.showLoading.emit(false);
          this.orderAccept.emit();
          this.autoPrinter();
        },
        (err: HttpErrorResponse) => {
          this.showLoading.emit(false);
          const error = err.error ? err.error.error.message : err.statusText;
          this.disabled = false;
          this.snackbarService.showMessageSnackbar(error);
          this.orderAccept.emit();
        }
      );
  }
}

我希望订阅中的print方法能够像在其他以相同方式写入的组件中一样显示打印的数据

0 个答案:

没有答案