DEV Community

Faisal Ahmed
Faisal Ahmed

Posted on • Edited on

Query Param Queryparam

 <button routerLink="/pre-launch-form" [queryParams]="{ offerId: offerData?.id }" class="button">Click Me</button>              

Enter fullscreen mode Exit fullscreen mode
this.router.navigate(['my-order'],{queryParams:{orderId: res.data._id}});              

Enter fullscreen mode Exit fullscreen mode
export class MyOrderComponent implements OnInit {
  // Store Data
  orderId: any;
  orderDetails: any;

  // Subscription
  private subRouteOne: Subscription;
  private subGetData1: Subscription;

  private readonly activatedRoute = inject(ActivatedRoute);
  private readonly productOrderService = inject(ProductOrderService);

  ngOnInit(): void {
    this.subRouteOne = this.activatedRoute.queryParamMap.subscribe((qParam) => {
      this.orderId = qParam.get('orderId');
      if (this.orderId) {
        this.getOrderById(this.orderId);
      }
    });
  }

  private getOrderById(id: string) {
    console.log('get id', id);
    // const select = 'courseModules';
    this.subGetData1 = this.productOrderService.getOrderById(id).subscribe({
      next: (res) => {
        if (res.success) {
          this.orderDetails = res.data;
          console.log('order details', this.orderDetails);
        }
      },
      error: (err) => {
        console.log(err);
      },
    });
  }

  /**
   * ON Destroy
   */
  ngOnDestroy(): void {
    if (this.subRouteOne) {
      this.subRouteOne.unsubscribe();
    }
    if (this.subGetData1) {
      this.subGetData1.unsubscribe();
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)