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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay